Bryant Likes's Blog

It's all about WebData

Recent Posts

Tags

News


  • Windows Live Alerts
    View Bryant Likes's profile on LinkedIn

    Me

    The posts on this weblog are provided "as is" with no warranties and confer no rights. The opinions expressed herin are the personal opinions of the individual authors and do not represent the views of Avanade in any way.

Community

Email Notifications

Archives

EIF and DebugView

One of the reasons I haven't been blogging lately is because I've been pretty busy with projects at work. One of the projects is a .Net application written in C#. I'm currently working on some of the logging functionality and I was inspired by the logging in FABRIQ. FABRIQ uses the Enterprise Instrumentation Framework to do its logging. At first I was overwhelmed by the amount of code FABRIQ used just to log an event, but I quickly saw the value in EIF once I started to play around with it.

One of the cool things about EIF is you can set what (where?) you log to at runtime (and change it while your app is running). The way EIF does this is to use Event Sinks. Out of the box, EIF comes with three of these events sinks: WMI, trace, and log. The trace event sink writes an event trace to the EIF trace log. The log event sink writes the event to the event log. You specify which types of events you want to write to which type of event sink in the EnterpriseInstrumentation.config file.

Ok, so now you know a little about EIF. Now in my case I wanted to be able to output trace information to my old friend DebugView. I didn't see an easy way to do this with EIF (although there might be one) so I wrote a custom event sink (which, btw, is easy to do). Below is the code for my custom event sink:


public class DebugEventSink : EventSink
{
  string[] columns;

  public DebugEventSink(IDictionary parameters, EventSource eventSource) : base(parameters, eventSource)
  {
    if (parameters.Contains("columns"))
    {
      string param = parameters["columns"] as string;
      if (param != null)
        columns = param.Split(",".ToCharArray());
    }
  }
  
  // Output the eventToRaise out to the debugger.
  public override void Write(object eventToRaise)
  {
    StringBuilder sb = new StringBuilder();
    Type t = eventToRaise.GetType();
    foreach (string column in columns)
    {
      PropertyInfo pi = t.GetProperty(column);
      if (pi != null)
        sb.Append(pi.GetValue(eventToRaise, null));
      sb.Append(" : ");
    }
    Debug.WriteLine(sb.ToString());
  }
}

Once I had created my custom event sink I could now add it to the EnterpriseInstrumentation.config file, setting the columns I wanted to output, and now DebugView is outputting the data I want to see. The nice thing is that I can turn this on when I want to debug something, turn it off when I don't, or just have it write to the EIF trace log so I can look at things later on.

All in all, very cool. I am now a fan of EIF and I owe some thanks to the FABRIQ crew for showing me this. Thanks!

Posted: Sep 30 2004, 12:42 PM by bryantlikes | with 4 comment(s)
Filed under:

Comments

bryantlikes said:

If you like that, then take a look at the http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/Logging.asp

And if you prefer something arguably better than EIF/MLAB then take a look at log4net at: http://sourceforge.net/projects/log4net/

Personally I think log4net is best, but that is my background and it comes preloaded with loads of event sinks and is very simple to use. Either way they are both essential to an enterprise solution.
# October 13, 2004 4:18 AM

bryantlikes said:

I tried almost the same thing, but I keep getting the following error:

Unable to read and validate the configuration file C:\Data\Personal\Tech-Ed\EIF\EIF\EnterpriseInstrumentation.config. The following type(s) cannot be loaded:
CustomSink.FileEventSink
Please check the event & eventSink element's type attribute in the configuration file, and that these types are correctly installed on the system.

Where else do I look to see where I went wrong?
# November 2, 2004 2:52 AM

geetanjali said:

Hi

I have implemented logging in the same way you are doing.

I am able to invok constructor of the CustomEventSink but i want to invoke different function instead.

Please tell me what changes I need to do in EnterpriseInstrumentaion.config file?

Regards

Geetanjali

# November 7, 2006 12:41 AM

geetanjali said:

Please add a reference of the Custom sink project to your web project

Geet

# November 7, 2006 12:48 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)