Wednesday, September 10, 2008

Enterprise Library Logging with WMI

In Enterprise Library for Microsoft (EntLib v3.1), you can use the WMI TraceListener (WMITraceListener class) to send logging events/statistics to the Windows Performance Monitor application.

Steps:

  1. Enable Instrumentation on the host: Start / All Programs / Microsoft Patterns & Practices / Enteprise Library 3.1 - May 2007 / Install Instrumentation
  2. With Enterprise Library Configuration, configure your app.config or web.config to use the WMI TraceListener.
  3. With Enterprise Library Configuration, add Instrumentation
  4. Edit the resulting config file (from previous steps) to set the instrumentation properties to "true": <instrumentationconfiguration performanceCountersEnabled="true"
    eventLoggingEnabled="true" wmiEnabled="true" />
  5. If you have subclassed LogEntry, make sure any custom typed Attributes are decorated with [IgnoreMember] (you'll have to have System.Management as a Reference)
  6. Run your program
  7. Add a new Counter in Windows Performance Monitor: Performance Object "Enterprise Library Logging Counter"; Select counters from list; Select your program's instance.
Troubleshooting:
  • If "Enterprise Library Logging Counter" isn't available in Performance Monitor, then you didn't Install Instrumentation in EntLib.
  • If you can't select an instance while adding the Counter, then your program probably isn't running, or something is preventing it from being instrumentable
  • If the application event log contains errors suggesting that you use IgnoreMember, then you are logging a subclassed EventLog that has Attributes with special types (the event log error will say which one). Or change the type of you attributes to string, int, etc... to avoid the problem.

No comments: