.netsystem.diagnosticsetwetw-eventsource

What is the best way to log exceptions using ETW?


Is there a standard way to log exceptions using ETW?

As far as I have seen the only way to do this is to log the message and possibly the inner exception message as there is not strongly typed parameter for the Exception type.


Solution

  • Use an extra Event and fire this event in the catch block and pass the exception message as a parameter to the Event

    [Event(1, Message = "Application Falure: {0}", Level = EventLevel.Error, Keywords = Keywords.Diagnostic)]
    public void Failure(string message) 
    { 
        if (this.IsEnabled())
        {
            this.WriteEvent(1, message); 
        }
    }
    

    Play with the Level and Keyword to control if you want to log it all the time or not.