本文整理汇总了C#中LogEventInfo类的典型用法代码示例。如果您正苦于以下问题:C# LogEventInfo类的具体用法?C# LogEventInfo怎么用?C# LogEventInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogEventInfo类属于命名空间,在下文中一共展示了LogEventInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Append
/// <summary>
/// Renders the log message including any positional parameters and appends it to the specified <see cref="StringBuilder" />.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
protected internal override void Append(StringBuilder builder, LogEventInfo logEvent)
{
if (NeedPadding())
{
builder.Append(ApplyPadding(logEvent.FormattedMessage));
}
else
{
if (logEvent.Parameters == null || logEvent.Parameters.Length == 0)
{
builder.Append(logEvent.Message);
}
else
{
if (logEvent.FormatProvider != null)
{
#if NETCF
builder.Append(String.Format(logEvent.FormatProvider, logEvent.Message, logEvent.Parameters));
#else
builder.AppendFormat(logEvent.FormatProvider, logEvent.Message, logEvent.Parameters);
#endif
}
else
{
#if NETCF
builder.Append(String.Format(logEvent.Message, logEvent.Parameters));
#else
builder.AppendFormat(logEvent.Message, logEvent.Parameters);
#endif
}
};
}
}
开发者ID:tdhieu,项目名称:openvss,代码行数:38,代码来源:Message.cs
示例2: AutoFlushTargetWrapperSyncTest1
public void AutoFlushTargetWrapperSyncTest1()
{
var myTarget = new MyTarget();
var wrapper = new AutoFlushTargetWrapper
{
WrappedTarget = myTarget,
};
myTarget.Initialize(null);
wrapper.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
bool continuationHit = false;
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit = true;
};
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.IsTrue(continuationHit);
Assert.IsNull(lastException);
Assert.AreEqual(1, myTarget.FlushCount);
Assert.AreEqual(1, myTarget.WriteCount);
continuationHit = false;
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.IsTrue(continuationHit);
Assert.IsNull(lastException);
Assert.AreEqual(2, myTarget.WriteCount);
Assert.AreEqual(2, myTarget.FlushCount);
}
开发者ID:Loopt,项目名称:NLog,代码行数:34,代码来源:AutoFlushTargetWrapperTests.cs
示例3: Append
/// <summary>
/// Renders the specified ASP.NET Item value and appends it to the specified <see cref="StringBuilder" />.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
if (Variable == null)
{
return;
}
HttpContext context = HttpContext.Current;
if (context == null)
{
return;
}
object value;
if (EvaluateAsNestedProperties)
{
var path = Variable.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
value = context.Items[path[0]];
foreach (var property in path.Skip(1))
{
var propertyInfo = value.GetType().GetProperty(property);
value = propertyInfo.GetValue(value, null);
}
}
else
{
value = context.Items[Variable];
}
builder.Append(Convert.ToString(value, CultureInfo.InvariantCulture));
}
开发者ID:dafanasiev,项目名称:NLog.Web,代码行数:38,代码来源:AspNetItemValueLayoutRenderer.cs
示例4: Write
/// <summary>
/// Writes the specified logging event to the <see cref="System.Diagnostics.Trace"/> facility.
/// If the log level is greater than or equal to <see cref="LogLevel.Error"/> it uses the
/// <see cref="System.Diagnostics.Trace.Fail(string)"/> method, otherwise it uses
/// <see cref="System.Diagnostics.Trace.Write(string)" /> method.
/// </summary>
/// <param name="logEvent">The logging event.</param>
protected override void Write(LogEventInfo logEvent)
{
if (logEvent.Level <= LogLevel.Debug)
{
Trace.WriteLine(this.Layout.Render(logEvent));
}
else if (logEvent.Level == LogLevel.Info)
{
Trace.TraceInformation(this.Layout.Render(logEvent));
}
else if (logEvent.Level == LogLevel.Warn)
{
Trace.TraceWarning(this.Layout.Render(logEvent));
}
else if (logEvent.Level == LogLevel.Error)
{
Trace.TraceError(this.Layout.Render(logEvent));
}
else if (logEvent.Level >= LogLevel.Fatal)
{
Trace.Fail(this.Layout.Render(logEvent));
}
else
{
Trace.WriteLine(this.Layout.Render(logEvent));
}
}
开发者ID:unhappy224,项目名称:NLog.IqMetrix,代码行数:34,代码来源:TraceTarget.cs
示例5: GetFormattedString
public override string GetFormattedString(LogWriteContext context, LogEventInfo info)
{
StringBuilder builder = new StringBuilder();
builder.Append("Sequence: ");
builder.Append(info.SequenceID);
builder.Append("\r\nDate/time: ");
builder.Append(info.TimeStamp.ToString(LogManager.DateTimeFormat));
builder.Append("\r\nLevel: ");
builder.Append(info.Level.ToString().ToUpper());
builder.Append("\r\nThread: ");
builder.Append(Environment.CurrentManagedThreadId);
builder.Append("\r\nLogger: ");
builder.Append(info.Logger);
builder.Append("\r\n------------------------\r\n");
builder.Append(info.Message);
if(info.Exception != null)
{
builder.Append("\r\n------------------------\r\n");
builder.Append(info.Exception);
}
builder.Append("\r\n------------------------\r\n");
builder.Append("Session: ");
builder.Append(context.Environment.ToJson());
return builder.ToString();
}
开发者ID:hermitdave,项目名称:MetroLog,代码行数:28,代码来源:FileSnapshotLayout.cs
示例6: Append
/// <summary>
/// Renders the selected process information.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
if(!_isInitialized)
throw new InvalidOperationException("required run Initialize method");
if (propertyInfo != null)
builder.Append(Convert.ToString(propertyInfo.GetValue(process, null), CultureInfo.InvariantCulture));
}
开发者ID:ExM,项目名称:NLog,代码行数:12,代码来源:ProcessInfoLayoutRenderer.cs
示例7: Write
/// <summary>
/// Writes the specified logging event to the attached debugger.
/// </summary>
/// <param name="logEvent">The logging event.</param>
protected override void Write(LogEventInfo logEvent)
{
if (Debugger.IsLogging())
{
Debugger.Log(logEvent.Level.Ordinal, logEvent.LoggerName, Layout.Render(logEvent) + "\n");
}
}
开发者ID:modulexcite,项目名称:SQLoogle,代码行数:11,代码来源:DebuggerTarget.cs
示例8: Write
/// <summary>
/// Does nothing. Optionally it calculates the layout text but
/// discards the results.
/// </summary>
/// <param name="logEvent">The logging event.</param>
public override void Write(LogEventInfo logEvent)
{
if (_formatMessage)
{
CompiledLayout.GetFormattedMessage(logEvent);
}
}
开发者ID:pallmall,项目名称:WCell,代码行数:12,代码来源:Null.cs
示例9: CreateClient
/// <summary>
/// First attemps to create a RollbarClient using config read from
/// appSettings. Uses properties of this class as overrides if specified.
/// </summary>
/// <param name="logEvent"></param>
/// <returns></returns>
private RollbarClient CreateClient(LogEventInfo logEvent)
{
var configuration = new Configuration(AccessToken);
if (!string.IsNullOrEmpty(Endpoint))
configuration.Endpoint = Endpoint;
if (Environment != null)
configuration.Environment = Environment.Render(logEvent);
if (Platform != null)
configuration.Platform = Platform.Render(logEvent);
if (Language != null)
configuration.Language = Language.Render(logEvent);
if (Framework != null)
configuration.Framework = Framework.Render(logEvent);
var client = new RollbarClient(configuration);
client.RequestStarting += RollbarClientRequestStarting;
client.RequestCompleted += RollbarClientRequestCompleted;
return client;
}
开发者ID:jmblab,项目名称:NLog.RollbarSharp,代码行数:31,代码来源:RollbarTarget.cs
示例10: FilteringTargetWrapperAsyncTest2
public void FilteringTargetWrapperAsyncTest2()
{
var myMockCondition = new MyMockCondition(false);
var myTarget = new MyAsyncTarget();
var wrapper = new FilteringTargetWrapper(myTarget, myMockCondition);
wrapper.Initialize(CommonCfg);
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
Action<Exception> continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(0, myTarget.WriteCount);
Assert.AreEqual(1, myMockCondition.CallCount);
continuationHit.Reset();
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(0, myTarget.WriteCount);
Assert.AreEqual(2, myMockCondition.CallCount);
}
开发者ID:ExM,项目名称:NLog,代码行数:30,代码来源:FilteringTargetWrapperTests.cs
示例11: GetMessageInner
public static string GetMessageInner(bool useJSON, Layout layout, LogEventInfo info)
{
if (!useJSON)
return layout.Render(info);
var logLine = new LogLine
{
TimeStampISO8601 = info.TimeStamp.ToUniversalTime().ToString("o", CultureInfo.InvariantCulture),
Message = info.FormattedMessage,
Level = info.Level.Name,
Type = "amqp",
Source = new Uri(string.Format("nlog://{0}/{1}", HostName, info.LoggerName))
};
logLine.AddField("exception", info.Exception);
if (info.Properties.Count > 0 && info.Properties.ContainsKey("fields"))
foreach (var kv in (IEnumerable<KeyValuePair<string, object>>) info.Properties["fields"])
logLine.AddField(kv.Key, kv.Value);
if (info.Properties.Count > 0 && info.Properties.ContainsKey("tags"))
foreach (var tag in (IEnumerable<string>) info.Properties["tags"])
logLine.AddTag(tag);
logLine.EnsureADT();
return JsonConvert.SerializeObject(logLine);
}
开发者ID:nslowes,项目名称:NLog.RabbitMQ,代码行数:28,代码来源:MessageFormatter.cs
示例12: WriteAsync
protected internal override sealed Task<LogWriteOperation> WriteAsync(LogWriteContext context, LogEventInfo entry)
{
try
{
// add...
List<LogEventInfo> toFlush = null;
lock (_lock)
{
this.Buffer.Add(entry);
// if...
if (this.Buffer.Count >= this.Threshold)
{
toFlush = new List<LogEventInfo>(this.Buffer);
this.Buffer = new List<LogEventInfo>();
}
}
// anything to flush?
if (toFlush != null)
return FlushAsync(context, toFlush);
else
return Task.FromResult(new LogWriteOperation(this, entry, true));
}
catch (Exception ex)
{
InternalLogger.Current.Error(string.Format("Failed to write to target '{0}'.", this), ex);
return Task.FromResult(new LogWriteOperation(this, entry, false));
}
}
开发者ID:hermitdave,项目名称:MetroLog,代码行数:30,代码来源:BufferedTarget.cs
示例13: Write
protected override void Write(LogEventInfo logEvent)
{
// A log event can be either an exception OR a message.
// If both were provided, then the exception takes precedence over the message.
if (logEvent.Exception != null)
{
Metadata metaData = null;
// Do we have any metadata
var bugsnagInterface = logEvent.Exception as IMetadata;
if (bugsnagInterface != null)
{
metaData = bugsnagInterface.Metadata;
}
AddFormattedMessageToMetadata(ref metaData, logEvent.FormattedMessage);
// Notify Bugsnag of this exception.
_baseClient.Value.Notify(logEvent.Exception, logEvent.Level.ToSeverity(), metaData);
}
else if (!string.IsNullOrWhiteSpace(logEvent.Message))
{
// We don't have an exception but we do have a message!
var exception = new BugsnagException(logEvent.Message);
_baseClient.Value.Notify(exception, logEvent.Level.ToSeverity());
}
}
开发者ID:PureKrome,项目名称:NLog.Bugsnag,代码行数:27,代码来源:BugSnagTarget.cs
示例14: Append
/// <summary>
/// Renders time in the 24-h format (HH:mm:ss.mmm) and appends it to the specified <see cref="StringBuilder" />.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
DateTime dt = logEvent.TimeStamp;
if (this.UniversalTime)
{
dt = dt.ToUniversalTime();
}
var culture = GetCulture(logEvent);
string timeSeparator;
string ticksSeparator;
if (culture != null)
{
#if !SILVERLIGHT
timeSeparator = culture.DateTimeFormat.TimeSeparator;
#else
timeSeparator = ":";
#endif
ticksSeparator = culture.NumberFormat.NumberDecimalSeparator;
}
else
{
timeSeparator = ":";
ticksSeparator = ".";
}
Append2DigitsZeroPadded(builder, dt.Hour);
builder.Append(timeSeparator);
Append2DigitsZeroPadded(builder, dt.Minute);
builder.Append(timeSeparator);
Append2DigitsZeroPadded(builder, dt.Second);
builder.Append(ticksSeparator);
Append4DigitsZeroPadded(builder, (int)(dt.Ticks % 10000000) / 1000);
}
开发者ID:CharlieBP,项目名称:NLog,代码行数:40,代码来源:TimeLayoutRenderer.cs
示例15: Write
/// <summary>
/// Does nothing. Optionally it calculates the layout text but
/// discards the results.
/// </summary>
/// <param name="logEvent">The logging event.</param>
protected internal override void Write(LogEventInfo logEvent)
{
if (_formatMessage)
{
CompiledLayout.GetFormattedMessage(logEvent);
}
}
开发者ID:kisflying,项目名称:kion,代码行数:12,代码来源:Null.cs
示例16: Write
/// <summary>
/// Writes the specified logging event to the attached debugger.
/// </summary>
/// <param name="logEvent">The logging event.</param>
protected internal override void Write(LogEventInfo logEvent)
{
if (Debugger.IsLogging())
{
Debugger.Log(logEvent.Level.Ordinal, logEvent.LoggerName, CompiledLayout.GetFormattedMessage(logEvent) + "\n");
}
}
开发者ID:kisflying,项目名称:kion,代码行数:11,代码来源:Debugger.cs
示例17: Write
/// <summary>
/// Does nothing. Optionally it calculates the layout text but
/// discards the results.
/// </summary>
/// <param name="logEvent">The logging event.</param>
protected override void Write(LogEventInfo logEvent)
{
if (this.FormatMessage)
{
this.Layout.Render(logEvent);
}
}
开发者ID:shadowca,项目名称:NLog,代码行数:12,代码来源:NullTarget.cs
示例18: Append
/// <summary>
/// Renders the specified ASP.NET User.Identity.AuthenticationType variable and appends it to the specified <see cref="StringBuilder" />.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
HttpContext context = HttpContext.Current;
if (context == null)
{
return;
}
if (context.User == null)
{
return;
}
if (context.User.Identity == null)
{
return;
}
if (!context.User.Identity.IsAuthenticated)
{
return;
}
builder.Append(context.User.Identity.AuthenticationType);
}
开发者ID:semirs,项目名称:CellAO,代码行数:30,代码来源:AspNetUserAuthTypeLayoutRenderer.cs
示例19: Write
protected override void Write(LogWriteContext context, LogEventInfo entry)
{
var message = Layout.GetFormattedString(context, entry);
switch(entry.Level)
{
case LogLevel.Trace:
MetroLogEventSource.Log.Trace(message);
break;
case LogLevel.Debug:
MetroLogEventSource.Log.Debug(message);
break;
case LogLevel.Info:
MetroLogEventSource.Log.Info(message);
break;
case LogLevel.Warn:
MetroLogEventSource.Log.Warn(message);
break;
case LogLevel.Error:
MetroLogEventSource.Log.Error(message);
break;
case LogLevel.Fatal:
MetroLogEventSource.Log.Fatal(message);
break;
}
}
开发者ID:onovotny,项目名称:MetroLog,代码行数:26,代码来源:EtwTarget.cs
示例20: AsyncTargetWrapperAsyncTest1
public void AsyncTargetWrapperAsyncTest1()
{
var myTarget = new MyAsyncTarget();
var targetWrapper = new AsyncTargetWrapper(myTarget);
((ISupportsInitialize)targetWrapper).Initialize();
((ISupportsInitialize)myTarget).Initialize();
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
targetWrapper.WriteLogEvent(logEvent, continuation);
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(1, myTarget.WriteCount);
continuationHit.Reset();
targetWrapper.WriteLogEvent(logEvent, continuation);
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(2, myTarget.WriteCount);
}
开发者ID:igalse,项目名称:NLog,代码行数:28,代码来源:AsyncTargetWrapperTests.cs
注:本文中的LogEventInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论