c# - 向 EventSource 中的所有 ETW 事件添加字段
问题描述
目前,我的 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]
方法对它们进行管道传输,它们会使输出出现乱码。上面的代码块是我发现的将字段添加到每个事件的唯一方法。必须有更好的方法,但我还没有想出完美的谷歌搜索来找出这是如何完成的。
解决方案
推荐阅读
- svn - 无法找到 svn 忽略属性以取消忽略文件
- php - 如何将特定的键值元素保留在数组中并删除其余部分?
- django - 构建自定义视图以向特定用户授予权限(不使用 ADMIN)
- python - 以 10 为基数的 int() 的无效文字:“字符串名称”
- node.js - 我想在 mongodb 中创建一个包含数组字段的文档
- oauth-2.0 - 如何使用先前获取的不透明格式的访问令牌获取 jwt 格式的访问令牌
- go - 将 map[string][]string 转换为 []map[string]interface{}
- scala - 与 spark 并行下载数据
- python - I have integrated a bash command into my Python code - how can I get this command to take an input from the shell?
- spring-boot - Spring Data Rest:自定义 JsonDeserializer 中的 @Autowire