Now you have a couple of new DLLs. If you are paying attention and looking through the code, you will notice that you have a new user control called "exceptionManagementEventLogInstaller."
This set of classes provides a great deal of functionality for just a single line of code on your part. For instance, if you publish an error you will get the following information written to your log file:
The computer name where the exception was created. This is great for client/server applications.
The date and time when the exception occurred.
Information on the thread where the exception was created.
The application domain name where the exception occurred. This is helpful when you have several applications writing to the same log file, such as the Windows event log.
The following are several benefits to using this set of classes:
You can publish exceptions with just one line of code in your Catch block.
It gives you a consistent interface for handling errors.
It lets you easily add new exception publishers.
It lets you add publishers without changing your code. These new publishers can reside in a separate component.
It gives you a way to easily redirect exceptions to different publishers via XML configuration files.
In their basic configuration, the exception classes publish errors in the Windows event log. I covered the event log back in Chapter 7. Of course, you can create your own publishers and redirect error-capturing text to any output you like.
As I mentioned in Chapter 7, it is best if you do not clog up the Windows event log file with all kinds of stuff. Besides this being wasteful, it makes it difficult to distinguish your log entries from entries of any other program running on your computer. You are better off defining your own publisher. The help file shows you how to do this easily enough. After reading this book, you certainly have enough knowledge to do so without too much trouble.
So, once you have included references to the new DLLs you created, you need just one line of code to set the exception ball rolling. Here it is—don't blink.
C#
catch(Exception e) { ExceptionManager.Publish(e); }
VB
Catch ex as Exception ExceptionManager.Publish(e);
That's it. Where it goes is defined by values in your <application name>.exe.config file. What gets published is defined by the default publisher or by you if you create a new publisher.
By the way, in keeping with the spirit of XML, you're able to publish exceptions in XML format as well. Pretty cool, isn't it?