本文整理汇总了C#中LoggingEvent类的典型用法代码示例。如果您正苦于以下问题:C# LoggingEvent类的具体用法?C# LoggingEvent怎么用?C# LoggingEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoggingEvent类属于命名空间,在下文中一共展示了LoggingEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Append
protected override void Append (LoggingEvent loggingEvent)
{
try
{
base.Append (loggingEvent);
if (maximumEntries == 0)
{
return;
}
lock (m_eventsList.SyncRoot)
{
int elementsToRemove = m_eventsList.Count - maximumEntries;
if (elementsToRemove > 0)
{
UnityEngine.Debug.Log ("Removing " + elementsToRemove + " elements.");
m_eventsList.RemoveRange (0, elementsToRemove);
}
}
}
catch(Exception e)
{
UnityEngine.Debug.LogError(e);
}
}
示例2: Push
public override void Push(LoggingEvent[] loggingEvents)
{
if (loggingEvents == null)
throw new ArgumentNullException("loggingEvents");
_queue.Enqueue(loggingEvents);
}
示例3: PushingWithNoTargetsShouldThrow
public void PushingWithNoTargetsShouldThrow()
{
var eventDispatcher = new DefaultEventDispatcher();
var loggingEvent = new LoggingEvent { Text = "Event" };
Executing.This(() => eventDispatcher.Push(loggingEvent, false)).Should().Throw<InvalidOperationException>();
}
示例4: Push
public override void Push(LoggingEvent[] loggingEvents)
{
foreach (var loggingEvent in loggingEvents)
{
Console.WriteLine(Format.Format(loggingEvent));
}
}
示例5: GetRequest
protected HttpWebRequest GetRequest(LoggingEvent[] loggingEvents)
{
var request = (HttpWebRequest)WebRequest.Create(Url);
request.KeepAlive = false;
request.Timeout = 5000;
request.ServicePoint.ConnectionLeaseTimeout = 5000;
request.ServicePoint.MaxIdleTime = 5000;
request.ServicePoint.ConnectionLimit = 50;
request.Accept = "application/json";
request.UserAgent = "Pulsus " + Constants.Version;
request.Method = "POST";
request.ContentType = "application/json";
var bytes = GetRequestBody(loggingEvents, Compress);
request.ContentLength = bytes.Length;
if (Compress)
request.Headers.Add("Content-Encoding", "gzip");
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
return request;
}
示例6: Post
public void Post(LoggingEvent[] loggingEvents)
{
var request = GetRequest(loggingEvents);
try
{
var response = request.GetResponse() as HttpWebResponse;
if (response == null)
throw new Exception("There was an error posting the server");
if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.Created && response.StatusCode != HttpStatusCode.Accepted)
throw new Exception(string.Format("The server returned a {0} status with the message: {1}", response.StatusCode, response.StatusDescription));
}
catch (WebException ex)
{
if (ex.Response == null)
throw new Exception(string.Format("Response Status: {0}, Description: {1}", ex.Status, ex.Message), ex);
var responseStream = ex.Response.GetResponseStream();
if (responseStream == null)
throw new Exception("GetResponseStream() returned null", ex);
var reader = new StreamReader(responseStream);
var responseContent = reader.ReadToEnd();
throw new Exception(string.Format("Response Status: {0}, Content: {1}", ex.Status, responseContent), ex);
}
}
示例7: AppendLoopOnAppenders
/// <summary>
/// Append on on all attached appenders.
/// </summary>
/// <param name="loggingEvent">The event being logged.</param>
/// <returns>The number of appenders called.</returns>
/// <remarks>
/// <para>
/// Calls the <see cref="IAppender.DoAppend" /> method on all
/// attached appenders.
/// </para>
/// </remarks>
public int AppendLoopOnAppenders(LoggingEvent loggingEvent)
{
if (loggingEvent == null)
{
throw new ArgumentNullException("loggingEvent");
}
// m_appenderList is null when empty
if (m_appenderList == null)
{
return 0;
}
if (m_appenderArray == null)
{
m_appenderArray = m_appenderList.ToArray();
}
foreach(IAppender appender in m_appenderArray)
{
try
{
appender.DoAppend(loggingEvent);
}
catch(Exception ex)
{
LogLog.Error(declaringType, "Failed to append to appender [" + appender.Name + "]", ex);
}
}
return m_appenderList.Count;
}
示例8: Convert
/// <summary>
/// Write the ASP.Net Cache item to the output
/// </summary>
/// <param name="writer"><see cref="TextWriter" /> that will receive the formatted result.</param>
/// <param name="loggingEvent">The <see cref="LoggingEvent" /> on which the pattern converter should be executed.</param>
/// <param name="httpContext">The <see cref="HttpContext" /> under which the ASP.Net request is running.</param>
/// <remarks>
/// <para>
/// Writes out the value of a named property. The property name
/// should be set in the <see cref="Mammothcode.Public.Core.Util.PatternConverter.Option"/>
/// property.
/// </para>
/// </remarks>
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent, HttpContext httpContext)
{
HttpRequest request = null;
try {
request = httpContext.Request;
} catch (HttpException) {
// likely a case of running in IIS integrated mode
// when inside an Application_Start event.
// treat it like a case of the Request
// property returning null
}
if (request != null)
{
if (Option != null)
{
WriteObject(writer, loggingEvent.Repository, httpContext.Request.Params[Option]);
}
else
{
WriteObject(writer, loggingEvent.Repository, httpContext.Request.Params);
}
}
else
{
writer.Write(SystemInfo.NotAvailableText);
}
}
示例9: EmailTemplateModel
public EmailTemplateModel(LoggingEvent loggingEvent)
{
if (loggingEvent == null)
throw new ArgumentNullException("loggingEvent");
LoggingEvent = loggingEvent;
HttpContextInformation = loggingEvent.GetData<HttpContextInformation>(Constants.DataKeys.HttpContext);
StackTrace = loggingEvent.GetData<string>(Constants.DataKeys.StackTrace);
SqlInformation = loggingEvent.GetData<SqlInformation>(Constants.DataKeys.SQL);
ExceptionInformation = loggingEvent.GetData<ExceptionInformation>(Constants.DataKeys.Exception);
GeneralSection = new Dictionary<string, object>();
LoadGeneralSection();
CustomData = loggingEvent.Data.Where(x => !x.Key.StartsWith("MS_", StringComparison.InvariantCultureIgnoreCase)).ToDictionary(x => x.Key, x => x.Value);
if (!CustomData.Any())
CustomData = null;
RequestSection = new Dictionary<string, object>();
LoadRequestSection();
LevelText = Enum.GetName(typeof (LoggingEventLevel), LoggingEvent.Level);
LevelClass = "green";
var loggingEventLevelValue = (int) loggingEvent.Level;
if (loggingEventLevelValue >= 40000 && loggingEventLevelValue <= 60000)
LevelClass = "yellow";
else if (loggingEventLevelValue > 60000)
LevelClass = "red";
Footer = string.Format(CultureInfo.InvariantCulture, "Pulsus | {0} | {1}", Constants.Version, Constants.WebSite);
}
示例10: NullDataValueShouldReturnDefaultValue
public void NullDataValueShouldReturnDefaultValue()
{
var loggingEvent = new LoggingEvent();
loggingEvent.Data.Add("test", null);
var value = loggingEvent.GetData<string>("test");
value.Should().Be.Null();
}
示例11: Append
protected override void Append(LoggingEvent loggingEvent)
{
if (string.Empty.Equals(loggingEvent.MessageObject))
return;
if (loggingEvent.MessageObject != null)
{
Messages.Add(loggingEvent.MessageObject.ToString());
}
}
示例12: SerializedDataShoudBeCorrectlyDeserialized
public void SerializedDataShoudBeCorrectlyDeserialized()
{
const string serializedData = "{ \"custom-data\" : { \"StringField\" : \"test\", \"IntField\" : 9 } }";
var loggingEvent = new LoggingEvent();
loggingEvent.Data = JsonConvert.DeserializeObject<IDictionary<string, object>>(serializedData);
var result = loggingEvent.GetData<CustomData>("custom-data");
result.Should().Not.Be.Null();
result.StringField.Should().Be("test");
result.IntField.Should().Be(9);
}
示例13: Decide
public override FilterDecision Decide(LoggingEvent loggingEvent)
{
if (loggingEvent.LoggerName.StartsWith("NServiceBus."))
{
if (loggingEvent.Level < Level.Warn)
{
return FilterDecision.Deny;
}
}
return FilterDecision.Accept;
}
示例14: Convert
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
if (HttpContext.Current == null)
{
writer.Write(SystemInfo.NotAvailableText);
}
else
{
Convert(writer, loggingEvent, HttpContext.Current);
}
}
示例15: Convert
/// <summary>
/// Write the TimeStamp to the output
/// </summary>
/// <param name="writer"><see cref="TextWriter" /> that will receive the formatted result.</param>
/// <param name="loggingEvent">the event being logged</param>
/// <remarks>
/// <para>
/// Pass the <see cref="LoggingEvent.TimeStamp"/> to the <see cref="IDateFormatter"/>
/// for it to render it to the writer.
/// </para>
/// <para>
/// The <see cref="LoggingEvent.TimeStamp"/> passed is in the local time zone, this is converted
/// to Universal time before it is rendered.
/// </para>
/// </remarks>
/// <seealso cref="DatePatternConverter"/>
override protected void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
try
{
m_dateFormatter.FormatDate(loggingEvent.TimeStamp.ToUniversalTime(), writer);
}
catch (Exception ex)
{
LogLog.Error(declaringType, "Error occurred while converting date.", ex);
}
}