Do we have any way to create generic EventSource

Topics: General, Using
Dec 22, 2015 at 11:57 AM
The class which is derived from EventSource in ETW or in semantic logging has attribute name which has to be given when the class is defined. If the name attribute it not present class name is used to identify the source.

Right now in the application if we want to have multiple providers I will have to define a new class inherited from EventSource. There is no way to configure the name.

The requirement is .

Can I have a generic provider class inherited from EventSource for which the name can be configured according to in which application it is used. This way I can have a single provider component used by multiple processes or services with configured name.

public sealed class MyEventSource: EventSource
{
    private static readonly Lazy<MyEventSource> Instance = new Lazy<MyEventSource>(() => new MyEventSource());

    private SemanticLoggingEventSource()
    {

    }


    public static MyEventSource Log
    {
        get { return Instance.Value; }
    }

    [Event(104, Message = "Information: Event Received {0}, {1}")]
    public void TraceInformation(string id, string strMessage)
    {
        bool b = IsEnabled();
        if (b) WriteEvent(104, id, strMessage);
    }
}
}

Thanks,
Vidhya