In Chapter 4, "Components and .NET Assemblies," we discuss the AppDomain class in detail. This class allows for response to events such as when an assembly is loaded or unloaded and when an unhandled exception occurs. When an unhandled exception occurs, it raises an UnhandledException event within the containing AppDomain . This event passes information back to your code in an UnhandledExceptionEventArgs object. This gives you one last chance to work with an exception, even if no Catch block exists to trap the error. Table 3.2 details the more important properties of the UnhandledExceptionEventArgs class. Table 3.2. Important Properties of the UnhandledExceptionEventArgs Class
An event handler may be attached to the UnhandledException event to take custom actions such as writing the exception-related information to a log file. A log maintained over a period of time may help you to analyze and identify patterns providing useful debugging information. Several methods may be used to log event- related information, including the following:
The Windows Event Log provides the most dependable method of logging, because it's a core part of the operating system with few dependencies. If you log to a file, an email, or a database, your logging might fail due to loss of network connectivity or file access. To log information to the Event Log, you can use the EventLog class. The EventLog class allows your code to write to the Windows Event Logs (Application, System, and Security) available in Windows 2000 and later versions of the operating system.
Table 3.3 details some of the more important members of the EventLog class. Table 3.3. Important Members of the EventLog Class
|