Share via


Walkthrough: Logging an Exception

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

This walkthrough demonstrates the steps to log exception information. Figure 1 illustrates the process.

Ff647187.5cfb65a5-81ad-485a-8ffe-245cb5d799c5(en-us,PandP.10).png

Figure 1
Logging an exception

An exception occurs in the QuickStart executable, and the Exception Handling Application Block uses the Log Only Policy. The policy is configured to run the logging handler. It formats the exception information and passes it to the Logging Application Block. It also has a PostHandlingAction of None. This causes the Exception Handling Application Block to return false to the QuickStart executable. When it detects that the return value is false, the QuickStart executable resumes execution.

To reproduce this scenario

  1. Create a new blank solution in Visual Studio.
  2. Add a Windows-based application project named ExceptionHandlingWithLoggingQuickStart to the solution.
  3. Add the Process and logExceptionButton_Click methods to the Windows Forms class. These methods are included in the QuickStart source code.
  4. Use the configuration tools to create a new application configuration file.
  5. Use the configuration tools to add the Exception Handling Application Block to the application.
  6. Add a new exception policy named Log Only Policy.
  7. Add the exception type System.Exception to the Log Only Policy.
  8. Configure the System.Exception exception type to have a PostHandlingAction of None.
  9. Add a logging handler for the System.Exception exception type.
  10. Use the configuration tools to add the Logging Application Block to the application.