我有一个示例代码,是我从MSDN借来的 https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.tracing.eventsource?view=netframework-4.7.2
除此之外,我所做的就是将这段代码导入Visual Studio控制台应用程序。
为启动跟踪会话,我尝试了两种方法:
description
甚至尝试过
netsh trace start provider={3CADFCE4-5E22-4102-BDC2-5AEA4198CD04}
(guids.txt仅具有此guid)
一旦吐出ETL,我就尝试使用WPA / netsh跟踪转换和Message Analyzer打开它们。这些都没有显示这些事件。
这是怎么了?
logman create trace sess -pf guids.txt -bs 1000 -nb 100 256 -ow -o tracefiles
我希望结果能显示出来,但我所看到的只是:
[EventSource(Name = "MyLogger", Guid = "3CADFCE4-5E22-4102-BDC2-5AEA4198CD04")]
class MyCompanyEventSource : EventSource
{
public static MyCompanyEventSource Log = new MyCompanyEventSource();
[Event(1, Level = EventLevel.Informational)]
public void Startup() { WriteEvent(1); }
[Event(2, Level = EventLevel.Informational)]
public void OpenFileStart(string fileName) { WriteEvent(2, fileName); }
[Event(3, Level = EventLevel.Informational)]
public void LogString(string text) { WriteEvent(3, text); }
}
static void Main(string[] args)
{
do
{
string name = MyCompanyEventSource.GetName(typeof(MyCompanyEventSource));
IEnumerable<EventSource> eventSources = MyCompanyEventSource.GetSources();
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.OpenFileStart("My Filename");
MyCompanyEventSource.Log.LogString("Random string");
Thread.Sleep(1000);
} while (true);
}