Starting a new project
If you’re one of the lucky few who never need to maintain existing applications, then you can leverage the project templates that ship out of the box with NTrace. As of the time this document was written, there are currently templates for C# Console applications,
class libraries, and WinForms applications with plans for project templates for WCF, ASP.NET, and WPF applications soon. Starting a project using the project templates sets everything up for you: all you need to do is write your code and add tracing calls.
How to add NTrace to existing code
Declare an ETW Provider
In order to have your application publish events to ETW, you must add a reference to the NTrace library to your project (in the %ProgramFiles%\NTrace folder or in your machine’s GAC) and include a static field that is of type NTrace.ClassicProvider. The name
you use for the variable isn’t really important, but the fact that it can be accessed by all of the classes in your assembly is. In practice, it is advised to use internal so that it is accessible from all of the classes in your assembly.
Tweak An Existing Project
In many cases, you’ll want to add the preprocessor to your existing code. In order to have the preprocessor kick in and do its magic, you’ll have to import the build instructions into your C# project. To do this, simply add properties registering your ETW provider
and replace your existing reference to Microsoft.CSharp.targets with one to NTrace.CSharp.Targets from the $(MSBuildExtensionsPath)\NTrace\<<version>> folder like so:
These values "register" your provider and tells the preprocessor how
To hook things up when it’s time to build.
<<fully-qualified provider variable name>>
<!—There will already be an Import at the bottom of your project, pointing to Microsoft.CSharp.targets. Change it to the following -->
<Import Project="$(MSBuildExtensionsPath)\NTrace\v2.0\NTrace.CSharp.targets" />
How to capture the output of your application's logging: