本文整理汇总了C#中NLog.LogEventInfo类的典型用法代码示例。如果您正苦于以下问题:C# LogEventInfo类的具体用法?C# LogEventInfo怎么用?C# LogEventInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogEventInfo类属于NLog命名空间,在下文中一共展示了LogEventInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
public void Log(LogLevel level, string message, params object[] arguments)
{
var info = new LogEventInfo(GetLevel(level), Key, message);
info.Parameters = arguments;
LogManager.GetLogger(Key).Log(info);
}
示例2: Write
/// <summary>
/// Format and output logvent
/// </summary>
/// <param name="logEvent">If caller is NLogConnector, <paramref name="logEvent"/></param>.properties will have a complete set of values of HashTag.Diagnostics.LogEvent
protected override void Write(LogEventInfo logEvent)
{
var msg = new Dictionary<object, object>();
if (logEvent.Exception != null)
{
msg["exception"] = logEvent.Exception;
}
if (logEvent.HasStackTrace && logEvent.StackTrace != null)
{
msg["stackTrace"] = logEvent.StackTrace;
}
if (logEvent.UserStackFrame != null)
{
msg["userStackFrame"] = logEvent.UserStackFrame;
msg["userStackFrameIndex"] = logEvent.UserStackFrameNumber;
}
foreach(var prop in logEvent.Properties)
{
msg[prop.Key] = prop.Value;
}
var id = msg["UUID"].ToString();
var s = JsonConvert.SerializeObject(msg,Formatting.Indented);
string fileName = Path.Combine(dropFolder, id.ToString()) + ".log";
File.WriteAllText(fileName, s);
}
示例3: Log
public static void Log(string loggerName, LogLevel logLevel, string eventID, string message)
{
LogEventInfo logEvent = new LogEventInfo(logLevel, _logger.Name, message);
logEvent.Properties["EventID"] = eventID;
logEvent.Properties["LoggerName"] = loggerName;
_logger.Log(typeof(EventLogger), logEvent);
}
示例4: CreateLogDocument
/// <summary>
/// The create log document.
/// </summary>
/// <param name="logEvent">
/// The log event.
/// </param>
/// <returns>
/// The <see cref="Document"/>.
/// </returns>
private Document CreateLogDocument(LogEventInfo logEvent)
{
var log = new Document();
log["Id"] = logEvent.SequenceID;
log["TimeStamp"] = logEvent.TimeStamp;
log["Level"] = logEvent.Level.ToString();
log["Message"] = logEvent.Message;
log["UserStackFrameNumber"] = logEvent.UserStackFrameNumber;
if (logEvent.UserStackFrame != null)
{
log["FileName"] = logEvent.UserStackFrame.GetFileName();
log["FileLineNumber"] = logEvent.UserStackFrame.GetFileLineNumber();
log["FileColumnNumber"] = logEvent.UserStackFrame.GetFileColumnNumber();
log["MethodName"] = logEvent.UserStackFrame.GetMethod().Name;
}
if (logEvent.Exception != null)
{
log["ExceptionMessage"] = logEvent.Exception.Message;
log["ExceptionHResult"] = logEvent.Exception.HResult;
log["ExceptionStackTrace"] = logEvent.Exception.StackTrace;
log["ExceptionSource"] = logEvent.Exception.Source;
}
log["UserEmail"] = logEvent.Properties["UserEmail"].ToString();
log["OrderId"] = logEvent.Properties["OrderId"].ToString();
log["PackageId"] = logEvent.Properties["PackageId"].ToString();
log["TransactionId"] = logEvent.Properties["TransactionId"].ToString();
return log;
}
示例5: Check
protected override FilterResult Check(LogEventInfo ev)
{
if (ev.TimeStamp.Hour >= FromHour && ev.TimeStamp.Hour <= ToHour)
return Result;
else
return FilterResult.Neutral;
}
示例6: Test4
public void Test4()
{
Layout l = new Layout("${rot13:${event-context:aaa}}");
LogEventInfo lei = new LogEventInfo(LogLevel.Info, "aaa", "bbb");
lei.Context["aaa"] = "HELLO";
Assert.AreEqual("URYYB", l.GetFormattedMessage(lei));
}
示例7: Append
/// <summary>
/// Renders the specified environmental information and appends it to the specified <see cref="T:System.Text.StringBuilder"/>.
/// </summary>
/// <param name="builder">The <see cref="T:System.Text.StringBuilder"/> to append the rendered data to.</param><param name="logEvent">Logging event.</param>
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
try
{
if (HttpContext.Current == null)
return;
var context = new HttpContextWrapper(HttpContext.Current);
if (context.Request.RequestContext == null)
return;
var work = context.Request.RequestContext.GetWorkContext();
if (work == null)
return;
ShellSettings settings;
if (!work.TryResolve(out settings))
return;
builder.Append("Tenant:");
builder.AppendLine(settings.Name);
}
catch
{
}
}
示例8: Append
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
var record = logEvent.Properties[NLogTraceWriter.RecordKey] as TraceRecord;
if (record != null)
{
if (Operation)
builder.Append(record.Operation);
if (Status)
builder.Append(record.Status.ToString());
if (StatusCode)
builder.Append(Convert.ToInt32(record.Status));
if (RequestId)
builder.Append(record.RequestId);
if (Operator)
builder.Append(record.Operator);
if (Kind)
builder.Append(record.Kind.ToString());
if (AcceptType)
builder.Append(record.Request.Headers.Accept.ToString());
if (Host)
builder.Append(record.Request.Headers.Host);
}
}
示例9: Write
protected override void Write(LogEventInfo logEvent)
{
if (logEvent.Level >= LogLevel.Warn)
{
_logs.Add(logEvent);
}
}
示例10: Append
protected override void Append( StringBuilder builder, LogEventInfo logEvent )
{
object value;
if (!logEvent.Properties.TryGetValue( NLogTraceWriter.RecordKey, out value ))
return;
var record = value as TraceRecord;
if (record == null)
return;
if (Operation)
builder.Append( record.Operation );
if (Status)
builder.Append( record.Status.ToString() );
if (StatusCode)
builder.Append( Convert.ToInt32( record.Status ) );
if (RequestId)
builder.Append( record.RequestId );
if (Operator)
builder.Append( record.Operator );
if (Kind)
builder.Append( record.Kind.ToString() );
}
示例11: Write
protected override void Write(LogEventInfo logEvent)
{
try
{
string message = Layout.Render(logEvent);
// echo to debug
Debug.WriteLine(message);
ScriptObject scriptMethod = null;
if (logEvent.Level == LogLevel.Info)
scriptMethod = _debugInfo;
else if (logEvent.Level == LogLevel.Warn)
scriptMethod = _debugWarn;
else if (logEvent.Level == LogLevel.Error)
scriptMethod = _debugError;
if (scriptMethod == null)
scriptMethod = _debugLog;
if (scriptMethod == null)
return;
// thread safe
Deployment.Current.Dispatcher.BeginInvoke(() =>
scriptMethod.InvokeSelf(message));
}
catch (Exception ex)
{
Debug.WriteLine("Error calling debug.log function: " + ex);
}
}
示例12: Write
protected override void Write(LogEventInfo logEventInfo)
{
if (DocumentStore == null)
DocumentStore = DependencyManager.GetInstance<IRavenDbContext>().DocumentStore;
var logEvent = new LogEvent
{
FormattedMessage = logEventInfo.FormattedMessage,
Level = logEventInfo.Level.Name,
TimeStamp = logEventInfo.TimeStamp
};
// Set exceptions
if (logEventInfo.Exception != null)
{
logEvent.Exception = logEventInfo.Exception.StackTrace;
if (logEventInfo.Exception.InnerException != null)
{
logEvent.InnerException = logEventInfo.Exception.InnerException.Message + "<br/>" + logEventInfo.Exception.InnerException.StackTrace;
}
}
using (var session = DocumentStore.OpenSession())
{
session.Store(logEvent);
session.SaveChanges();
}
}
示例13: Info
public static LogEventInfo Info(string loggerName, string message)
{
LogEventInfo evt = new LogEventInfo(LogLevel.Info, loggerName, message);
evt.Properties["message"] = message;
return evt;
}
示例14: MetricsCollector
public MetricsCollector()
{
var config = ConfigurationManager.GetSection("CollectdWinConfig") as CollectdWinConfig;
if (config == null)
{
LogEventInfo logEvent = new LogEventInfo(LogLevel.Error, Logger.Name, "Cannot get configuration section");
logEvent.Properties.Add("EventID", ErrorCodes.ERROR_CONFIGURATION_EXCEPTION);
Logger.Log(logEvent);
return;
}
_runReadThread = false;
_runWriteThread = false;
var registry = new PluginRegistry();
_plugins = registry.CreatePlugins();
_interval = config.GeneralSettings.Interval;
if (_interval <= 10)
_interval = 10;
_timeout = config.GeneralSettings.Timeout;
if (_timeout <= _interval)
_timeout = _interval*3;
bool storeRates = config.GeneralSettings.StoreRates;
_aggregator = new Aggregator(_timeout, storeRates);
_collectedValueQueue = new Queue<CollectableValue>();
_queueLock = new Object();
}
示例15: CreateToolWindow
private Window CreateToolWindow(IDockableUserControl control)
{
object userControlObject = null;
Window toolWindow;
try
{
_logger.Trace("Loading \"{0}\" ClassId {1}", control.Caption, control.ClassId);
toolWindow = _vbe.Windows.CreateToolWindow(_addin, _DockableWindowHost.RegisteredProgId,
control.Caption, control.ClassId, ref userControlObject);
}
catch (COMException exception)
{
var logEvent = new LogEventInfo(LogLevel.Error, _logger.Name, "Error Creating Control");
logEvent.Exception = exception;
logEvent.Properties.Add("EventID", 1);
_logger.Error(logEvent);
return null; //throw;
}
catch (NullReferenceException exception)
{
Debug.Print(exception.ToString());
return null; //throw;
}
var userControlHost = (_DockableWindowHost)userControlObject;
toolWindow.Visible = true; //window resizing doesn't work without this
EnsureMinimumWindowSize(toolWindow);
toolWindow.Visible = false; //hide it again
userControlHost.AddUserControl(control as UserControl);
return toolWindow;
}