Entering Configuration Information

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.

These procedures explain how to configure the Exception Handling Application Block. Properties associated with the nodes appear in the right pane of the Configuration Console or the Properties window of the Visual Studio Configuration Editor. For details of the schema for the Exception Handling Application Block configuration, see Source Schema for the Exception Handling Application Block.

To add the Exception Handling Application Block

  1. Open the configuration file. For more information, see Configuring Enterprise Library.
  2. Right-click Application Configuration, point to New, and then click Exception Handling Application Block.

To configure an exception handling policy

  1. To add an exception handling policy, right-click the Exception Handling Application Block node, point to New, and then click Exception Policy. This creates an exception handling policy node. By default, this exception policy is named Exception Policy.
  2. (Optional) Rename the policy. Right-click the policy node, click Rename, and then type the policy name you want.
  3. To add an exception type to a policy, right-click the policy node, point to New, and then click Exception Type. Select the exception type in the Type Selector dialog box. To filter the list, in the Filter edit box type the string to use to filter the list, for example type "string" to filter for all classes containing the word "string". If the type you want is not listed, click Load from File or Load from GAC to find the assembly that contains the type you want. Click OK. This creates the Exception node. The node's properties are displayed in the properties pane.
  4. Select the PostHandlingAction you want. The PostHandlingAction determines what action will occur after the exception handling chain completes. By default, the PostHandlingAction is set to NotifyRethrow. Valid values are the following:
    • None. The application block executes all handlers for this exception and returns false to the application at the point that the HandleException method was invoked. Applications checking this value resume execution.
    • NotifyRethrow. The application block executes all handlers for this exception and returns true to the application at the point that the HandleException method was invoked. Applications checking this value rethrow the original exception.
    • ThrowNewException. The application block executes all handlers for this exception and throws the exception that exists after the final handler runs.
  5. To add an exception handler, right click the Exception node, point to New, and then click the exception handler type that you want:
    • Custom Handler. This exception handler lets you configure custom exception handlers. Click Load Assembly in the Type Selector to add a custom handler.
    • Logging Handler. This exception handler formats exception information and uses the Logging Application Block to log exception information. The Logging Application Block is automatically added to the application configuration when you select a logging handler. For more information, see The Logging Application Block.
    • Replace Handler. This exception handler replaces one exception with another.
    • Wrap Handler. This exception handler wraps one exception within another exception.

Configuring Exception Handlers

After you add an exception handler to the exception, you can configure it. These procedures explain how to configure custom, logging, replace, and wrap exception handlers.

To configure a custom exception handler

  1. Click the custom handler node in the tree view.
  2. Click the ellipsis button (****…) in the Attributes property section of the right pane.
  3. In the EditableKeyValue Collection Editor dialog box, click Add to add a new name/value pair.
  4. In the right pane of the EditableKeyValue Collection Editor dialog box, enter the key name and the value of the property.
  5. Add more name/value pairs as appropriate, and then click OK.
  6. In the Name property section of the configuration tools, change the name of the exception handler if you want to. The default name is Custom Handler.
  7. Click the ellipsis button (****…) in the Type property section of the right pane. To filter the list, in the Filter edit box type the string to use to filter the list, for example type "string" to filter for all classes containing the word "string". If the type you want is not included in the Assemblies folder, click Load from File or Load from GAC in the Type Selector to find the assembly that contains the type you want.

To configure a logging exception handler

  • Click the Logging Handler node, and then enter the following values that are displayed in the properties pane:
    • Name. This is the name of the logging exception handler. The default name is Logging Handler. You can change the name if you want to.
    • EventID. This is the ID number of the event that will be logged. The default value is 100. You can enter a different value if you want.
    • FormatterType. This is the fully qualified name of the formatter used to format the exception information before it is logged. Click the ellipsis button (****…) and use the Type Selector to choose the formatter you want to use.
    • LogCategory. This is the name of the log category that the event is assigned to. The default name is Default Category. You can enter the name of a different category if you want to.
    • Priority. This is the priority of the log message. The Logging Application Block can be configured to filter log messages depending on their priority.
    • Severity. This is the severity of the event. The default value is Error. To select another level of severity, click an entry in the drop-down list. The other choices are Critical, Warning, Information, Verbose, Start, Stop, Suspend, Resume, and Transfer.
    • Title. This is the title of the log entry. The default value is Enterprise Library Exception Handling. You can change the title if you want to.
    • UseDefaultLogger. This setting determines of the logging handler will write exception details to a default log file or to separate files with GUIDs as the file names. The default is False, which means it uses GUID-named files. When set to True, the handler writes every log event and exception to the same file.

To configure a replace handler

  • Click the Replace Handler node, and then enter the following values that are displayed in the properties pane:
    • Name. This is the name of the replace handler. The default name is Replace Handler. You can change the name if you want to.
    • ExceptionMessage. This is the text of the message to be used with the replacement exception. This property is optional.
    • ReplaceExceptionType. This is the fully qualified name of the exception type that will replace the original exception. The default type is System.Exception. If this is not correct, use the Type Selector to click the type you want.

To configure a wrap handler

  • Click the Wrap Handler node, and then enter the following values that are displayed in the properties pane:
    • Name. This is the name of the wrap handler. The default name is Wrap Handler. You can change the name if you want to.
    • ExceptionMessage. This is the text of the message to be used with the wrapping exception. This property is optional.
    • WrapExceptionType. This is the fully qualified name of the exception type that will wrap the original exception. The default type is System.Exception. If this is not correct, use the Type Selector to click the type you want.