从MSDN文档中,Write-event仅支持int和string param类型。我想将用户创建的ct传递给Write-event,如何获得此功能?什么是正确的序列化器来实现这个功能?
答案 0 :(得分:2)
有几种选择:
EventData
结构并传递给WriteEventCore
(必须位于unsafe
内) - TPL目前使用此方法。答案 1 :(得分:0)
在Windows 10中(也向后移植到Win7 / 8.1),自.Net 4.6起支持Rich Payload Data:
// define a ‘plain old data’ class
[EventData]
class SimpleData {
public string Name { get; set; }
public int Address { get; set; }
}
[EventSource(Name = "Samples-EventSourceDemos-RuntimeDemo")]
public sealed class RuntimeDemoEventSource : EventSource
{
// define the singleton instance of the event source
public static RuntimeDemoEventSource Log = new RuntimeDemoEventSource();
// Rich payloads only work when the self-describing format
private RuntimeDemoEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { }
// define a new event.
public void LogSimpleData(string message, SimpleData data) { WriteEvent(1, message, data); }
}
RuntimeDemoEventSource.Log.LogSimpleData(
"testMessage",
new SimpleData() { Name = "aName", Address = 234 });
阅读博客和文档了解更多详情。