Tracing to ETW with Enterprise Library v5

While I was looking for a way to use ETW Tracing using the logging EntLib infrastructure, I found out that using a handy trace listener like SystemDiagnosticsTraceListenerData configured to use the built-in EventProviderTraceListener was all that I needed. With just setting the event provider ID which is simply a GUID added to the initializeData attribute and I'm good to go.

This is an example of the config section configured with the above settings:   

<listeners>

<add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.SystemDiagnosticsTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

type="System.Diagnostics.Eventing.EventProviderTraceListener, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

traceOutputOptions="ThreadId" name="ETW Trace Listener" initializeData="{D2FAAB3F-5D61-42B5-A014-D1A658BEE0B7}" />

</listeners>

 

Now you can simply use it by calling Logger.Write(message) o or any other logging call. You can also add this listener to any category you want and optionally use formatters as well.

Remember that you can activate your event provider by opening and "Admin" command prompt and running:

logman create trace myApplication -p {D2FAAB3F-5D61-42B5-A014-D1A658BEE0B7} -o .\etwtrace.etl -ow
logman start myApplication

You can check that your data collector set is up and running by inspecting with Performance Monitor (perfmon.msc) and look into "Data Collector Sets\User Defined). There you may check for many properties of your process and also verify the etl file location which by default is in Windows\System32 folder with a file name like "etwtrace_000001.etl".

After you are done with the tracing, simply end by typing:

logman stop aExpense
logman delete aExpense

The information saved to the .etl file may be consumed by different tools described below and we can also use the tracerpt to generate an xml file and inspect the traced data or analyzing with WPA (Windows Performance Analyzer).

 

 

No Comments