Share via


Extending the Logging Application Block

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.

The Logging Application Block is designed to suit a variety of applications and to provide the most commonly used logging functions. You can extend the application block through designated extension points. Typically, these are custom classes, written by you, that implement a particular interface or derive from an abstract class. Because these custom classes exist in your application space, you do not need to modify or rebuild the application block. Instead, you designate your extensions using configuration settings. Additionally, with extension points, you can adapt the application block to suit the needs of any particular application. You can extend the capabilities of the application block by adding custom trace listeners, filters, and formatters.

Note

You can also use the Application Block Software Factory to extend this application block. For more information, see the patterns & practices Community Site on CodePlex.

The following procedure describes the general approach to extend the Logging Application Block.

To extend the Logging Application Block

Create a new custom class and add it to your project.

Make sure that the class implements the required interfaces, constructors, and methods.

Add the custom object to the configuration of the Logging Application Block using the Enterprise Library configuration tools:

  • Specify your custom class as the type name.
  • Specify any custom configuration properties by modifying the attributes of the object.

To create a custom formatter

  1. Create a new class, and then add it to your project.
  2. (Optional) To use elements without fully qualifying each one, you can add the following using statement (C#) or Imports statement (Visual Basic) to the top of your source code file.
  3. Specify that the class implements ILogFormatter.
  4. Add the class attribute ConfigurationElementType. Specify the type CustomFormatterData as the attribute parameter.
  5. Add a constructor that has parameter of type NameValueCollection.
  6. Add the Format method to your class, and then implement the required behavior.

For more details about how to extend the Logging Application Block, with an example that shows how to create a custom event sink, see Walkthrough: Creating a Custom Trace Listener.