Chapter 6. The Logging and Instrumentation Application Block


THE LAST CHAPTER touched on the fact that it is very common for an application to have to log information. For example, it isn't unusual for an application to log exceptions that occur. I mentioned that, while handling exceptions is the responsibility of the Exception Handling Application Block, logging the exceptions is the responsibility of the Logging and Instrumentation Application Block. Unfortunately, like caching, logging is often an afterthought to the design of the application and only gets added to the application after it has already been deployed and issues start to arise. When this occurs, logging is often "slammed" into the application in a haphazard manner.

The Logging and Instrumentation Application Block is meant to make it easy to architect and develop a solution with very flexible logging capabilities. Regrettably, I have heard from many developers and architects that the Logging and Instrumentation Application Block appears to be too complex to fit their needsthey feel that it is just too much to deal with when all they need to do is log a message to a file or the event log. This is an unfortunate assessment.

In this chapter I will attempt to change this perception by first explaining the reasons for the classes that exist in the Logging and Instrumentation Application Block. More importantly, however, I will attempt to show that any complexity that exists because of these classes is "hidden" from most developers who will use the block. If your only need is to write to a file or an event log, the only code that you may ever need to write is Logger.Write(string). If your applications have more complex logging needs, the Logging and Instrumentation Application Block has been designed to accommodate those needs without causing an undue burden on those developers who don't need it. And best of all, the application is automatically indifferent to changes that may occur with respect to the final location for the log messages and how to get them there.

This chapter has a lot of code samples, but don't confuse this with the need to write a lot of code to take advantage of the features in the Logging and Instrumentation Application Block. Quite the opposite is true. The capabilities that this block provides in terms of its extensibility are the very reasons why the average developer who works with this block can be hidden from any complex logging needs. That is the main point of this chapter.




Fenster Effective Use of Microsoft Enterprise Library(c) Building Blocks for Creating Enterprise Applications and Services 2006
Effective Use of Microsoft Enterprise Library: Building Blocks for Creating Enterprise Applications and Services
ISBN: 0321334213
EAN: 2147483647
Year: 2004
Pages: 103
Authors: Len Fenster

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net