本文整理汇总了C#中NLog.LogEventInfo.SetStackTrace方法的典型用法代码示例。如果您正苦于以下问题:C# LogEventInfo.SetStackTrace方法的具体用法?C# LogEventInfo.SetStackTrace怎么用?C# LogEventInfo.SetStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLog.LogEventInfo
的用法示例。
在下文中一共展示了LogEventInfo.SetStackTrace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
internal static void Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)
{
if (targets == null)
{
return;
}
#if !NET_CF
StackTraceUsage stu = targets.GetStackTraceUsage();
if (stu != StackTraceUsage.None && !logEvent.HasStackTrace)
{
StackTrace stackTrace;
#if !SILVERLIGHT
stackTrace = new StackTrace(StackTraceSkipMethods, stu == StackTraceUsage.WithSource);
#else
stackTrace = new StackTrace();
#endif
int firstUserFrame = FindCallingMethodOnStackTrace(stackTrace, loggerType);
logEvent.SetStackTrace(stackTrace, firstUserFrame);
}
#endif
int originalThreadId = Thread.CurrentThread.ManagedThreadId;
AsyncContinuation exceptionHandler = ex =>
{
if (ex != null)
{
if (factory.ThrowExceptions && Thread.CurrentThread.ManagedThreadId == originalThreadId)
{
throw new NLogRuntimeException("Exception occurred in NLog", ex);
}
}
};
for (var t = targets; t != null; t = t.NextInChain)
{
if (!WriteToTargetWithFilterChain(t, logEvent, exceptionHandler))
{
break;
}
}
// Destroy the objects
logEvent.Dispose();
}
示例2: Write
internal static void Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)
{
if (targets == null)
return;
#if !NETCF
bool needTrace = false;
bool needTraceSources = false;
int nst = targets.NeedsStackTrace;
if (nst > 0)
needTrace = true;
if (nst > 1)
needTraceSources = true;
StackTrace stackTrace = null;
if (needTrace && !logEvent.HasStackTrace)
{
int firstUserFrame = 0;
stackTrace = new StackTrace(STACK_TRACE_SKIP_METHODS, needTraceSources);
for (int i = 0; i < stackTrace.FrameCount; ++i)
{
System.Reflection.MethodBase mb = stackTrace.GetFrame(i).GetMethod();
if (mb.DeclaringType == loggerType)
{
firstUserFrame = i + 1;
}
else
{
if (firstUserFrame != 0)
break;
}
}
logEvent.SetStackTrace(stackTrace, firstUserFrame);
}
#endif
for (TargetWithFilterChain awf = targets; awf != null; awf = awf.Next)
{
Target app = awf.Target;
FilterResult result = FilterResult.Neutral;
try
{
FilterCollection filterChain = awf.FilterChain;
for (int i = 0; i < filterChain.Count; ++i)
{
Filter f = filterChain[i];
result = f.Check(logEvent);
if (result != FilterResult.Neutral)
break;
}
if ((result == FilterResult.Ignore) || (result == FilterResult.IgnoreFinal))
{
if (InternalLogger.IsDebugEnabled)
{
InternalLogger.Debug("{0}.{1} Rejecting message because of a filter.", logEvent.LoggerName, logEvent.Level);
}
if (result == FilterResult.IgnoreFinal)
return;
continue;
}
}
catch (Exception ex)
{
InternalLogger.Error("FilterChain exception: {0}", ex);
if (factory.ThrowExceptions)
throw;
else
continue;
}
try
{
app.Write(logEvent);
}
catch (Exception ex)
{
InternalLogger.Error("Target exception: {0}", ex);
if (factory.ThrowExceptions)
throw;
else
continue;
}
if (result == FilterResult.LogFinal)
return;
}
}
示例3: ProcessLogEventInfo
protected virtual void ProcessLogEventInfo(LogLevel logLevel, string loggerName, [Localizable(false)] string message, object[] arguments, int? eventId)
#endif
{
var ev = new LogEventInfo();
ev.LoggerName = (loggerName ?? this.Name) ?? string.Empty;
#if !NET_CF
if (this.AutoLoggerName)
{
var stack = new StackTrace();
int userFrameIndex = -1;
MethodBase userMethod = null;
for (int i = 0; i < stack.FrameCount; ++i)
{
var frame = stack.GetFrame(i);
var method = frame.GetMethod();
if (method.DeclaringType == this.GetType())
{
// skip all methods of this type
continue;
}
if (method.DeclaringType.Assembly == systemAssembly)
{
// skip all methods from System.dll
continue;
}
userFrameIndex = i;
userMethod = method;
break;
}
if (userFrameIndex >= 0)
{
ev.SetStackTrace(stack, userFrameIndex);
if (userMethod.DeclaringType != null)
{
ev.LoggerName = userMethod.DeclaringType.FullName;
}
}
}
if (eventType.HasValue)
{
ev.Properties.Add("EventType", eventType.Value);
}
if (relatedActiviyId.HasValue)
{
ev.Properties.Add("RelatedActivityID", relatedActiviyId.Value);
}
#endif
ev.TimeStamp = TimeSource.Current.Time;
ev.Message = message;
ev.Parameters = arguments;
ev.Level = this.forceLogLevel ?? logLevel;
if (eventId.HasValue)
{
ev.Properties.Add("EventID", eventId.Value);
}
Logger logger;
if (this.LogFactory != null)
{
logger = this.LogFactory.GetLogger(ev.LoggerName);
}
else
{
logger = LogManager.GetLogger(ev.LoggerName);
}
logger.Log(ev);
}
示例4: Log
public void Log(LoggingData loggingData)
{
var logEvent = new LogEventInfo();
logEvent.LoggerName = loggingData.LoggerName;
logEvent.Message = loggingData.Message;
logEvent.TimeStamp = loggingData.TimeStamp;
if (!string.IsNullOrEmpty(loggingData.ExceptionString))
logEvent.Exception = new Exception(loggingData.ExceptionString);
if (loggingData.Properties != null && loggingData.Properties.Count > 0)
{
var properties = loggingData.Properties;
var dict = new Dictionary<object, object>();
foreach(var k in properties.Keys.OfType<string>())
{
properties.Add(k, properties[k]);
}
}
if(loggingData.LocationInfo != null)
{
var locationInfo = loggingData.LocationInfo;
var lineNumber = 0;
int.TryParse(locationInfo.LineNumber, out lineNumber);
logEvent.SetStackTrace(new StackTrace(new StackFrame(locationInfo.FileName, lineNumber)), 0);
}
LogLevel level;
if (!s_LevelDict.TryGetValue(loggingData.Level, out level))
level = LogLevel.Info;
logEvent.Level = level;
m_Logger.Log(logEvent);
}