我正在开发一个 ETW 侦听器来侦听系统中所有可用的事件源。
Q1:请在下面找到示例代码:
providerName = "ETW-TEST-APPLICATION";
sessionName = "ETW-TEST-APPLICATION";
using (var session = new TraceEventSession(sessionName, null))
{
try
{
session.StopOnDispose = true;
session.BufferSizeMB = 100;
Console.CancelKeyPress +=
delegate(object sender, ConsoleCancelEventArgs e) { session.Dispose(); };
using (source = new ETWTraceEventSource(sessionName, TraceEventSourceType.Session))
{
var parser = new DynamicTraceEventParser(source);
parser.AddDynamicProvider(new ProviderManifest(Environment.CurrentDirectory +
"\\ETWApplicationRegister." +
providerName +
".etwManifest.man"));
parser.All += delegate(TraceEvent data)
{
Console.WriteLine("--------------------------------------------------------------");
Console.WriteLine("ProviderName : " + data.ProviderName);
Console.WriteLine("ProviderGuid : " + data.ProviderGuid);
Console.WriteLine("EventID : " + data.ID);
Console.WriteLine("Level : " + data.Level);
Console.WriteLine("Channel : " + data.Channel);
Console.WriteLine("Task : " + data.Task);
Console.WriteLine("TaskName : " + data.TaskName);
Console.WriteLine("TimeStamp : " + data.TimeStamp);
Console.WriteLine("FormattedMessage : " + data.FormattedMessage);
Console.WriteLine("PayLoad : " + data.PayloadByName("jsonArgs"));
Console.WriteLine("--------------------------------------------------------------");
};
session.EnableProvider(providerGuid);
source.Process(); //On execution of this statement system listens to the events
}
}
}
此代码适用于一个事件源,即“ETW-TEST-APPLICATION”。我希望此侦听器用于多个事件源“ETW-TEST-APPLICATION2”、“ETW-TEST-APPLICATION3”等。
请让我知道可用于实现这一目标的选项。我尝试使用线程但没有工作。
Q2:另外让我知道我是否可以有多个 session.EnableProvider,我只想启用信息和错误消息,但忽略警告消息 session.EnableProvider(providerGuid,TraceEventLevel.Informal); session.EnableProvider(providerGuid,TraceEventLevel.Error);