Microsoft Enterprise Instrumentation Framework(EIF) - Quick Guide

The Microsoft EIF is a bunch of assemblies for .Net that make your life easy when it comes to instrumenting your program, by this I mean tracing facilities, writing to the event log, and many other things.
As this is a quick guide I will tell you only how to get up and running with the Event Log and Windows Trace in the quickest way possible.
The EIF is capable of many things so having a good look at the docs is essential, but if you are like me you want to get using something as quickly as possible in its simplest form then work on the advanced features later, this guide may help.
I spent a few days trying to develop my own tracing and event log code but it just did not work right. For example, try to write your own code that will automatically work out your assembly's pathname and put it in the event log. I could not do it without some very messy workarounds.
Included with EIF is a thing called 'Windows Trace' this basically a binary log file that you can write to without worrying about performance. So even your production code can trace, and support staff can access this information.
Obtaining and Installing EIF
Download and install 'Microsoft Enterprise Instrumentation Framework'
There is a very good seminar also available 'Using the Enterprise Instrumentation Framework' which I recommend you watch.
Using EIF in your code
Add References in your project to the following assemblies:
Add the following usings to any code that will use it :
  1. using Microsoft.EnterpriseInstrumentation;  
  2. using Microsoft.EnterpriseInstrumentation.Schema; 
Add a new class to your project, I call mine EnterpriseInstrumentationProjectInstaller.cs this is used when registering your assembly.
Change the new class definition to:
  1. [System.ComponentModel.RunInstaller(true)]  
  2. public class EnterpriseInstrumentationProjectInstaller : Microsoft.EnterpriseInstrumentation.ProjectInstaller  
the class does not need any code in it.
These are the standard built-in events you can raise:
  1. AdminMessageEvent.Raise("message");  
  2. AuditMessageEvent.Raise("message");  
  3. ErrorMessageEvent.Raise("message", 0, "error code");  
  4. TraceMessageEvent.Raise("message");  
Registering your assembly and creating the configuration file
  1. Build your project 
  2. Run the VS command prompt in output folder
  3. Run InstallUtil.exe <assemally file name> (If you need to run this againg you can uninstall first with InstallUtil.exe /u <assemally file name>)
  4. A file 'EnterpriseInstrumentation.config' will be created, move it into project directory and include it in the project
  5. Set up post build event:
copy "$(projectdir)EnterpriseInstrumentation.config" "$(targetdir)EnterpriseInstrumentation.config" this will copy the configuration file to the target directo ry when you build.
Configure your project's EnterpriseInstrumentation.config
Add the required elements to the "defaultSoftwareElementFilter" filter
  1. <filter name="defaultSoftwareElementFilter" description=" A default filter for the Software Element event sources.">  
  2. <eventCategoryRef name="All Events">  
  3. <eventSinkRef name="traceSink" />  
  4. <eventSinkRef name="logSink" />  
  5. </eventCategoryRef>  
  6. </filter> 
This will use the event log and windows trace.
Enable Windows trace
When you install EIF windows trace is disabled by default to enable it edit C:\Program Files\Microsoft Enterprise Instrumentation\Bin\Trace Service\TraceSessions.config and set enabled="true".
Viewing the Windows trace file
Included in EIF is a sample 'C:\Program Files\Microsoft Enterprise Instrumentation\Samples\Trace Viewer\TraceViewer.exe' this can be used to view the trace file located at 'C:\Program Files\Microsoft Enterprise Instrumentation\Bin\Trace Service\Logs\TraceLog.log'
That's it; even if you only use EIF as described here it still offers better functionality than any code most people have time to write.