目前,我的 ETW 事件定义如下:
public class MyEventSource: EventSource
{
[Event(1, Level=Info)]
public void WriteMyEvent(string Message)
{
WriteEvent(1, Message);
}
[Event(2, Level=Info)]
public void WriteOtherEvent(string Details)
{
WriteEvent(2, Details);
}
}
我想为调用者不需要传入的这两个事件添加一个字段。它是在应用程序配置中定义的静态字符串。我发现除了将其添加到修饰函数WriteEvent
的参数之外,没有其他方法可以将其添加到每个调用中。[Event]
public class MyEventSource: EventSource
{
public static readonly string MyDefault = "something";
[Event(1, Level=Info)]
public void WriteMyEvent(string Message, string Default = null)
{
// Ignore input "Default", use "MyDefault" instead
WriteEvent(1, Message, MyDefault);
}
[Event(2, Level=Info)]
public void WriteOtherEvent(string Details, string Default = null)
{
// Ignore "Default"
WriteEvent(2, Details, MyDefault);
}
}
如果我通过基本[NonEvent]
方法对它们进行管道传输,它们会使输出出现乱码。上面的代码块是我发现的将字段添加到每个事件的唯一方法。必须有更好的方法,但我还没有想出完美的谷歌搜索来找出这是如何完成的。