我正在编写一个处理windows ETW事件的应用程序。
logman
并配置要写入的事件
.etl
日志文件。
我的应用程序读取这些
.etl文件
文件,对其进行处理,然后删除该文件。
我需要一种机制将ETW事件写回.etl文件,以便稍后处理。
我怎样才能写一本书
Microsoft.Diagnostics.Tracing.TraceEvent
对象(通过
DynamicTraceEventParser
返回
到磁盘(理想情况下,返回到
想到的解决方案:
-
将失败事件写回
.etl文件
-
在发生任何单个事件处理错误时,只需保留整个事件文件,并让成功的记录处理两次。-不幸的是,我们的处理操作不是幂等的,所以这将不起作用(我们不能允许记录被处理两次)
-
将事件写回ETW事件存储——我对此持开放态度,但更喜欢选项1
(简化)代码:
// For each .etl file
foreach (string fullFileName in eventFileNames)
{
// Load the .etl file
using (var source = new ETWTraceEventSource(fileFullName))
{
var parser = new DynamicTraceEventParser(source);
parser.All += delegate (TraceEvent traceEvent)
{
bool proccessingSucceeded = ProcessEvent(traceEvent); // Processing code that can fail
if (!proccessingSucceeded)
{
// TODO: figure out a way to write this event back to disk (.etl file) to be processed later
}
};
source.Process();
}
}