The AnalyticTrace sample demonstrates how to implement End-to-End (E2E) tracing using Event Tracing for Windows (ETW) and the ETWTraceListener that is provided with this sample. The sample is based on the Getting Started and includes ETW tracing.
Note
The set-up procedure and build instructions for this sample are located at the end of this topic.
Each trace source in the System.Diagnostics tracing model can have multiple trace listeners that determine where and how the data is traced. The type of listener defines the format in which trace data is logged. The following code sample shows how to add the listener to configuration.
Before using this listener, an ETW Trace Session must be started. This session can be started by using Logman.exe or Tracelog.exe. A SetupETW.bat file is included with this sample so that you can set up the ETW Trace Session along with a CleanupETW.bat file for closing the session and completing the log file.
Note
The setup procedure and build instructions for this sample are located at the end of this topic. For more information about these tools, see https://go.microsoft.com/fwlink/?LinkId=56580
When using the ETWTraceListener, traces are logged in binary .etl files. With ServiceModel tracing turned on, all generated traces appear in the same file. Use Service Trace Viewer Tool (SvcTraceViewer.exe) for viewing .etl and .svclog log files. The viewer creates an end-to-end view of the system that makes it possible to trace a message from its source to its destination and point of consumption.
The ETW Trace Listener supports circular logging. To enable this feature, go to Start, Run and type cmd to start a command console. In the following command, replace the <logfilename> parameter with the name of your log file.
The -f and -max switches are optional. They specify the binary circular format and max log size of 1000MB respectively. The -p switch is used to specify the trace provider. In our example, "{411a0819-c24b-428c-83e2-26b41091702e}" is the GUID for "XML ETW Sample Provider".
To start the session, type in the following command.
Console
logman start Wcf
After you have finished logging, you can stop the session with the following command.
To use the RegisterProvider.bat, SetupETW.bat and CleanupETW.bat commands, you must run under a local administrator account. If you are using Windows Vista or later, you must also run the command prompt with elevated privileges. To do so, right-click the command prompt icon, then click Run as administrator.
Before running the sample, run RegisterProvider.bat on the client and server. This sets up the resulting ETWTracingSampleLog.etl file to generate traces that can be read by the Service Trace Viewer. This file can be found in the C:\logs folder. If this folder does not exist, it must be created or no traces are generated. Then, run SetupETW.bat on the client and server computers to begin the ETW Trace Session. The SetupETW.bat file can be found under the CS\Client folder.
Learn how Event Viewer provides a convenient and accessible location for you to observe events that occur. Access event information quickly and conveniently. Learn how to interpret the data in the event log.