本文整理汇总了C#中NLog类的典型用法代码示例。如果您正苦于以下问题:C# NLog类的具体用法?C# NLog怎么用?C# NLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NLog类属于命名空间,在下文中一共展示了NLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayError
private static void DisplayError(string error, NLog.Logger logger = null)
{
if (null != logger)
{
logger.Error(error);
}
else
{
Console.Error.WriteLine(error);
}
}
示例2: GetExceptionDetails
/// <summary>
/// This expects a web context; without it, the method will exit early.
/// </summary>
/// <param name="logEvent"></param>
/// <returns></returns>
public static string GetExceptionDetails(NLog.LogEventInfo logEvent)
{
if (HttpContext.Current == null
|| HttpContext.Current.Request == null
|| HttpContext.Current.Server == null) { return ""; }
var serverVariables = HttpContext.Current.Request.ServerVariables;
var lastError = HttpContext.Current.Server.GetLastError();
string errorMessage = (lastError == null) ? logEvent.FormattedMessage : lastError.InnerException.ToString();
var errorDetails = new StringBuilder();
errorDetails.AppendFormat("{0}<br /><br />", errorMessage);
// This helps give meaningful data in the case of "File does not exist" errors
errorDetails.AppendFormat("File Path: {0}<br /><br />", HttpContext.Current.Request.FilePath);
// Stack trace
if (logEvent.StackTrace != null)
errorDetails.AppendFormat("<i>Stack Trace:</i><br />{0}<br /><br />", logEvent.StackTrace.ToString());
else if (logEvent.Exception != null)
errorDetails.AppendFormat("<i>Stack Trace:</i><br />{0}<br /><br />", logEvent.Exception.Message + logEvent.Exception.StackTrace.ToString());
// Server variables
errorDetails.AppendFormat("<i>Server Variables:</i><br />");
foreach (String s in serverVariables.AllKeys)
errorDetails.AppendFormat("<p><span>{0,-10}<span>: <b>{1}</b></p>", s, serverVariables[s]);
return errorDetails.ToString();
}
示例3: Write
protected override void Write(NLog.Common.AsyncLogEventInfo logEvent)
{
if ( logEvent.LogEvent.Level > LogLevel.Warn && logEvent.LogEvent.Exception != null )
{
Elmah.ErrorSignal.FromCurrentContext().Raise(logEvent.LogEvent.Exception);
}
}
示例4: Write
protected override void Write(NLog.Common.AsyncLogEventInfo logEvent)
{
base.Write(logEvent);
if (LogReceived != null)
LogReceived(logEvent);
}
示例5: CreateLogEventInfo
private LogEventInfo CreateLogEventInfo(NLog.LogLevel level, string message, IDictionary<string, object> dictionary, Exception exception)
{
LogEventInfo logEvent = new LogEventInfo(level, _logger.Name, message);
foreach (var item in dictionary)
{
logEvent.Properties[item.Key] = item.Value;
}
if (exception != null)
{
logEvent.Properties["error-source"] = exception.Source;
if (exception.TargetSite != null)
{
if (exception.TargetSite.DeclaringType != null)
{
logEvent.Properties["error-class"] = exception.TargetSite.DeclaringType.FullName;
}
logEvent.Properties["error-method"] = exception.TargetSite.Name;
}
logEvent.Properties["error-message"] = exception.Message;
if (exception.InnerException != null)
{
logEvent.Properties["inner-error-message"] = exception.InnerException.Message;
}
}
return logEvent;
}
示例6: LumberjackMessageBuilder
public LumberjackMessageBuilder(NLog.Logger logger, string source, string appId, string component)
{
Logger = logger;
Source = source;
AppId = appId;
Component = component;
}
示例7: Write
protected override void Write(NLog.Common.AsyncLogEventInfo[] logEvents)
{
foreach (var ev in logEvents)
{
NumEvents++;
}
}
示例8: Write
protected override void Write(NLog.Common.AsyncLogEventInfo logEvent)
{
base.Write(logEvent);
if (RecieveLog != null)
RecieveLog(logEvent);
}
示例9: LoggerMark
/// <summary>
/// Instantiates an instance of the LoggerMark class.
/// </summary>
/// <param name="location">The location of the mark.</param>
/// <param name="logger">The logger to log the mark to.</param>
public LoggerMark(string location, NLog.Logger logger)
{
_id = _nextId++;
_location = location;
_logger = logger;
_logger.Trace("Enter " + location + " : " + _id);
_watch = Stopwatch.StartNew();
}
示例10: PackageService
public PackageService(
IServerPackageRepository repository,
IPackageAuthenticationService authenticationService,
NLog.ILogger logger)
{
_serverRepository = repository;
_authenticationService = authenticationService;
_logger = logger;
}
示例11: Write
public static void Write(object element, int depth, NLog.Logger log)
{
if (log.IsTraceEnabled)
{
ObjectDumper dumper = new ObjectDumper(depth);
dumper.WriteObject(null, element);
log.Trace(dumper.builder);
}
}
示例12: DeployBatchRunner
public DeployBatchRunner(NLog.Logger logger, ISystemSettings systemSettings, IDeployStateManager deployStateManager, IDeployRunner deployRunner, IDeployQueueManager deployQueueManager, IDeployRequestManager deployRequestManager, ICleanupManager cleanupManager)
{
_logger = DIHelper.VerifyParameter(logger);
_systemSettings = DIHelper.VerifyParameter(systemSettings);
_deployStateManager = DIHelper.VerifyParameter(deployStateManager);
_deployRunner = DIHelper.VerifyParameter(deployRunner);
_deployQueueManager = DIHelper.VerifyParameter(deployQueueManager);
_deployRequestManager = DIHelper.VerifyParameter(deployRequestManager);
_cleanupManager = DIHelper.VerifyParameter(_cleanupManager);
}
示例13: LogEvent
public LogEvent(NLog.LogEventInfo logEventInfo)
{
LoggerName = logEventInfo.LoggerName;
TimeStamp = logEventInfo.TimeStamp;
Level = logEventInfo.Level.ToString();
LogMessage = logEventInfo.FormattedMessage;
ToolTip = logEventInfo.FormattedMessage;
Exception = logEventInfo.Exception;
SetColors(logEventInfo);
}
示例14: Write
protected override void Write(NLog.LogEventInfo logEvent) {
var msg = AppendException(logEvent.FormattedMessage, logEvent.Exception);
_buffer.Add(new LogMessage {
Level = logEvent.Level,
Message = msg,
Source = logEvent.LoggerName,
Timestamp = logEvent.TimeStamp
});
}
示例15: Append
protected override void Append(StringBuilder builder, NLog.LogEventInfo logEvent)
{
var actionName = string.Empty;
if (HttpContext.Current != null)
{
actionName = HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString();
}
builder.Append(actionName);
}