Categories in the Logging Application Block

I have wrestled with a while on providing guidance for the use of categories in the LAB – it’s not that I had trouble understanding it, so much so as the name ‘category’ made things somewhat counterintuitive – however I’ve only realized that issue in hindsight.

I just finished working up an application that imports a large volume of financial data on a regular basis.  It has a primary log file, which provides a blow by blow description of what it did – it also puts out two summaries, one to my email account, and an even briefer one as an SMS message to my phone.

So I had three categories, FinancialLoader, Summary, and SMS.  Then it hit me!  A better name than category would be Stream, i.e. each of these names identifies a stream of information being emitted from the application.  I’d noticed that while I was getting the behavior I wanted, it seemed odd to say that the detailed summary messages were members of both the Summary and FinancialLoader categories, even though my specific goal was to have detailed summary information sent to my email and to the main log file, whereas SMS message went only to my phone.  When I changed my thinking to saying my app had three streams of logging output, and individual messages were directed to one or more streams, the model seemed to become a lot simpler.

My two cents is to think Stream everywhere you see the word Category in the LAB –  it seems to fit far better, and simplifies the whole concept –  you’re looking at the generation of a LogEntry which you want sent to one or more streams.

Published Monday, September 03, 2007 11:01 AM by MarkMMullin
Filed Under:

Comments