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 path name and put it in the event log. I could not do it without some very messy work arounds.

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

Go to http://www.microsoft.com/downloads/search.aspx and search for '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:

Microsoft.EnterpriseInstrumentation
Microsoft.EnterpriseInstrumentation.Schema
System.Configuration.Install

Add the following usings to any code that will use it :

using Microsoft.EnterpriseInstrumentation;
using Microsoft.EnterpriseInstrumentation.Schema;

Add a new class to your project, I call mine EnterpriseInstrumentationProjectInstaller.cs this is used when registering your assembily.

Change the new class definition to:

[System.ComponentModel.RunInstaller(true)]
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:

AdminMessageEvent.Raise("message");
AuditMessageEvent.Raise("message");
ErrorMessageEvent.Raise("message", 0, "error code");
TraceMessageEvent.Raise("message");

Registering your assemibly 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

<filter name="defaultSoftwareElementFilter" description=" A default filter for the Software Element event sources.">
<eventCategoryRef name="All Events">
<eventSinkRef name="traceSink" />
<eventSinkRef name="logSink" />
</eventCategoryRef>
</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 then any code most people have time to write.

Cheers!