First off, it has been a long time since I’ve last blogged. I have been very busy working on some other endeavors and I was on vacations for a few weeks. I am now working on some new blog posts and samples so I can get back into the swing of things.
Recently, I have been working with Enterprise Library for .net 2.0. I was able to get basic logging set up and working with little effort using this static method call:
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(oLogger);
Were oLogger is an instance of Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry. To get this to work, all I had to do was add a reference to Microsoft.Practices.EnterpriseLibrary.Logging and I was all set.
Now, I was trying to add a category so I can separate out tracing messages from error messages. The call looks like this:
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(oLogger, “Trace”);
With “Trace” being a string for the category.
When I try to build this inside Visual Studios 2005, I get an “unknown system exception”.
I am not really sure why this is happening. I’m guessing it is because internally categories are a Generic Collection and for whatever reason when I define a category the BizTalk compiler can not handle it?
I was able to find a simple work around that accomplished my goal. I created a simple .net helper class to wrap the static method call. Rather than using the overload to the Write method that takes in a category, I am now able to add the category to the collection. The helper method looks like this:
static public void myLog(Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry Message, string Category)
{
// Clear the collection first to make sure nothing is already in there
Message.Categories.Clear();
// Add the one category needed for logging
Message.Categories.Add(Category);
// Make the static method call for logging
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Message);
}
I’m now able to set up two categories in the configuration file to accept trace events and error conditions.