【发布时间】:2016-12-24 00:45:00
【问题描述】:
C# 6.0、.NET Framework 4.6.1、调试模式。
我为 EventLogTraceListener 实例设置了 TraceOptions.Callstack 值,但在 Windows 事件查看器中看不到调用堆栈。
这是我的简单代码:
public static string GetMsgHeaders() {
string currentMethodName = MethodBase
.GetCurrentMethod().Name;
Console.Out.WriteLine("The {0} method was called!",
currentMethodName);
if (!EventLog.SourceExists("sharp_sandbox")) {
EventLog.CreateEventSource("sharp_sandbox",
"Application");
}
EventLogTraceListener listener = new
EventLogTraceListener("sharp_sandbox");
listener.TraceOutputOptions = TraceOptions.DateTime
| TraceOptions.Callstack;
Trace.Listeners.Add(listener);
Trace.Write("Trace.Write");
Trace.WriteLine("Trace.WriteLine");
Trace.TraceWarning("Trace.TraceWarning");
Trace.TraceError("Trace.TraceError");
Trace.TraceInformation("Trace.TraceInformation");
listener.Close();
return "ABCDEF";
}
但我得到的信息没有调用堆栈,例如:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="sharp_sandbox" />
<EventID Qualifiers="0">0</EventID>
<Level>4</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2016-08-17T09:48:40.367843800Z" />
<EventRecordID>13778</EventRecordID>
<Channel>Application</Channel>
<Computer>Win10x64-VS.spb.gpsm.ru</Computer>
<Security />
</System>
<EventData>
<Data>Trace.TraceInformation</Data>
</EventData>
</Event>
为什么没有调用堆栈信息?
【问题讨论】:
标签: c# .net logging trace tracelistener