除此之外,我所做的只是将此代码导入 Visual Studio 控制台应用程序。
为了启动跟踪会话,我尝试了两种方法:
netsh trace start provider={3CADFCE4-5E22-4102-BDC2-5AEA4198CD04}
甚至尝试过
logman create trace sess -pf guids.txt -bs 1000 -nb 100 256 -ow -o tracefiles
(guids.txt 有这个唯一的 guid)
吐出 ETL 后,我尝试使用 WPA/netsh 跟踪转换和消息分析器打开它们。这些都没有显示这些事件。
这里有什么问题?
[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);
}
我希望结果会出现,但我看到的只是:
[0]8664.6194::2019-04-03 21:18:34.125 [MSNT_SystemTrace]
[0]8664.6194::2019-04-03 21:18:34.125 [MSNT_SystemTrace]
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***
[0]0000.0000::2019-04-03 21:18:34.125 []***