I have a C# solution which spans many, many projects. I created a tracing class that inherits from Systme.Diagnostics.Tracing.EventSource, called MyCustomEventSource, which handles most of my tracing events. I want to create subclasses of this class for each project, so that I can implement events relevant to specific projects.
I am also writing an ETW consumer where I can easily listen to events from the different components of my system.
But my consumer doesn't recognize events correctly: when I listen to MyCustomEventSource, the EventName field of each event is set to the name of the method, and FormattedMessage is set to the Message attribute. Example:
[Event(1,
Message = "The configuration parameter \"{0}\" was loaded with a value of {1}.",
Level = EventLevel.Informational,
Task = Tasks.Configuration,
Keywords = Keywords.Diagnostics)]
public void ConfigParameterLoaded(string name, string value)
{
WriteEvent(1, name, value);
}
If I listen to MyCustomEventSource, and an app calls ConfigParameterLoaded, then I get an event whose name is ConfigParameterLoaded, and its FormattedMessage is "The configuration parameter "x" was loaded with a value of y."
This is fine.
But, if I create a similar method on the subclass of MyCustomEventSource and trigger events from this subclass, my EventName will always be "EventSourceMessage", and the FormattedMessage will always be null.
I figure this is probably because System.Diagnostics.Tracing.EventAttribute doesn't have AttributeUsage(Inherited=true).
My question is: is there some way to get around this, and get the correct information when triggering events from a subclass?