We're using the NuGet pacakge of the Microsoft EventSource Library (1.0.24) to log events for the event viewer.
Given the following method definitions, for example, of a class inherited from EventSource, the resulting event viewer entries appear with the Task Category fields populated as specified by the Task = XYZ parameter:
public sealed class EventLogEventSource : EventSource
{
static public EventLogEventSource Log = new EventLogEventSource();
...
[Event( 1, Keywords = Keywords.Debug, Message = "Custom Message={0}",
Channel = EventChannel.Admin, Task = Tasks.CustomCategory1, Opcode = EventOpcode.Extension )]
public void CustomEvent1( string strMessage ) { WriteEvent( 1, strMessage ); }
[Event( 2, Keywords = Keywords.Debug, Message = "Custom Message={0}",
Channel = EventChannel.Admin, Task = Tasks.CustomCategory2, Opcode = EventOpcode.Extension )]
public void CustomEvent2( string strMessage ) { WriteEvent( 2, strMessage );
...
}
public class Tasks
{
public const EventTask CustomCategory1 = (EventTask)0x1;
public const EventTask CustomCategory2 = (EventTask)0x2;
}
...
EventLogEventSource.Log.CustomEvent1( "test1" );
EventLogEventSource.Log.CustomEvent2( "test2" );
...
The framework allows one to very easily and declaratively define all the relevant details to be included with each logged entry.
Although this works well, we would also like to be able to vary the eventID values when writing to the event log under the same category. For example, the earlier .Net incarnation of writing to the event log (EventLog Class), provides a more flexible interface to control the eventIDs and task categories:
public void WriteEntry( message, EventLogEntryType type, int eventID, short category )
Is there something analogous in ETW / EventSource to write to the event log with the ability to specify EventID values for the same category?
As an example of what we're trying to achieve, here's a snapshot of the logged events with different Event IDs for the same Task Category (Server):