Search code examples
traceazure-service-fabricazure-diagnostics

Setting ETW event level in service fabric tracing


When you create a service fabric application project using visual studio, you get an implementation of EventSource (called ServiceEventSource). For example, here is one of the method implementation:

    private const int ServiceRequestStopEventId = 6;
    [Event(ServiceRequestStopEventId, Level = EventLevel.Informational, Message = "Service request '{0}' finished", Keywords = Keywords.Requests)]
    public void ServiceRequestStop(string requestTypeName)
    {
        WriteEvent(ServiceRequestStopEventId, requestTypeName);
    }

As you can see, this method has Event attribute which has Level argument set.

  1. Where would I set that Level argument value?
  2. I am thinking that setting this Level's argument value will show how much output gets generated. Am I correct?
  3. Can I modify this Level argument value dynamically at run time and at will?

Solution

    1. You can set Level only in the Event attribute.
    2. The amount of output getting generated depends on consumers of logs. If there are no consumers or listeners, event will not be generated at any level. We can say that level depends on amount of output, but only if there are consumers of such event.
    3. No, you can't modify the level dynamically. To do this, you could have two methods with the same signature and different levels.

    You can find all the interesting information about ETW and its configuration here.