Reputation: 11
From MSDN documentation, Write-event supports only int and string param types. I want to pass a user-created ct to Write-event, how to get this functionality? What would be the right serializer to achieve this functionality?
Upvotes: 1
Views: 837
Reputation: 624
There are several options:
EventData
struct and pass to WriteEventCore
(has to be inside unsafe
) - TPL currently uses this method.Upvotes: 2
Reputation: 28826
In Windows 10 (also backported to Win7/8.1) there is support for Rich Payload Data since .Net 4.6:
// 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 });
Read the blog and document for more details.
Upvotes: 1