Reputation: 26266
I have this class for triggering ETW events:
public sealed class EventSourceWriter : EventSource
{
public static EventSourceWriter Logger = new EventSourceWriter();
[Event(1, Version = 0, Level = EventLevel.Informational)]
public void Log(string Log)
{
WriteEvent(1, Log);
}
}
As you can see, I set the EventLevel
on top of the Log
method as attribute value. Is there a way I can set it dynamically to log different EventLevels to same Event?
The idea is to see all generic logs on same table as output when an agent captures the ETW
events.
Upvotes: 0
Views: 399
Reputation: 624
As mike-z has pointed out for .NET 4.6 you might archive that by using dynamic events, but in this case those events won't be included into the manifest, and not all of ETW tools have been updated to support self-describing events yet.
But generally you are writing your EventSource class like this to archive that:
public sealed class EventSourceWriter : EventSource
{
public static EventSourceWriter Logger = new EventSourceWriter();
[Event(1, Level = EventLevel.Informational)]
public void LogInformational(string message)
{
WriteEvent(1, message);
}
[Event(2, Level = EventLevel.Warning)]
public void LogWarning(string message)
{
WriteEvent(2, message);
}
[Event(3, Level = EventLevel.Error)]
public void LogError(string message)
{
WriteEvent(3, message);
}
}
Upvotes: 1