PostSharp 6.4 / / Post­Sharp Documentation / Logging / Configuring Specific Logging Frameworks / Logging to ETW

Logging to ETW

This article shows how to use PostSharp Logging and Event Tracing for Windows (ETW) together.

If you run your application, you should now see a detailed log in a file named nlog.log. If your application is a console application, you should also see the log in the console.

This topic contains the following sections:

Targeting ETW

To target ETW with PostSharp Logging:

  1. Add PostSharp logging to your codebase as described in Adding Detailed Logging to your Solution.

  2. Add the PostSharp.Patterns.Diagnostics.Tracing package to your startup project.

  3. In the application startup file, include the following namespace imports:

    using PostSharp.Patterns.Diagnostics;
    using PostSharp.Patterns.Diagnostics.Backends.EventSource;

    In the application startup method, include the following code:

    var eventSourceBackend = new EventSourceLoggingBackend(new PostSharpEventSource());
    if (eventSourceBackend.EventSource.ConstructionException != null)
        throw eventSourceBackend.EventSource.ConstructionException;

As a result of this procedure, PostSharp Logging will emit records to the ETW event source named PostSharp-Patterns-Diagnostics. You now need to attach a listener to this event source.

Listening to ETW events

ETW is a very complex system and explaining it is beyong the scope of this documentation. Let's just show how you can collect and view ETW events on your development machine.

We will use a tool named PerfView developed by Microsoft.

To collect and view PostSharp Logging logs using PerfView:

See Also