Feed Icon  

Contact

  • Bryant Likes
  • Send mail to the author(s) E-mail
  • twitter
  • View Bryant Likes's profile on LinkedIn
  • del.icio.us
Get Microsoft Silverlight
by clicking "Install Microsoft Silverlight" you accept the
Silverlight license agreement

Hosting By

Hot Topics

Tags

Open Source Projects

Archives

Ads

EIF and DebugView

Posted in General at Thursday, September 30, 2004 5:42 AM Pacific Daylight Time

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!

Ping

Posted in General at Tuesday, September 14, 2004 2:53 AM Pacific Daylight Time

I'm still here. :)

I've been quiet lately due to some projects at work, a pregnant wife at home, and an upcoming election (read: politcal blogs). I've been getting a lot of feedback about the RsWebParts and the GotDotNet site has had a lot of activity (the workspace membership is maxed out even after I upped it once and there are about 20 requests still pending). I'm hoping to get back into it soon and I'm thinking I would like to appoint a couple of people to admins in the group so that the load can be distributed.