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 supply the most commonly used logging functions. 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
The Application Block Software Factory can also be used to extend this block. For more information, see Application Block Software Factory.
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.
- Create the custom object in the Enterprise Library Configuration Console.
- 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
Create a new class, and then add it to your project.
(Optional) To use elements without fully qualifying the element reference, you can add the following using statement (C#) or Imports statement (Visual Basic) to the top of your source code file.
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; using Microsoft.Practices.EnterpriseLibrary.Logging; using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
'Usage Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration Imports Microsoft.Practices.EnterpriseLibrary.Logging Imports Microsoft.Practices.EnterpriseLibrary.Logging.Configuration
Note
For Visual Basic projects, you can also use the References page of the Project Designer to manage references and imported namespaces. To access the References page, select a project node in Solution Explorer, then on the Project menu, click Properties. When the Project Designer appears, click the References tab.
Specify that the class implements ILogFormatter.
Add the class attribute ConfigurationElementType. Specify the type CustomFormatterData as the attribute parameter.
[ConfigurationElementType(typeof(CustomFormatterData))] public class MyFormatter : ILogFormatter
'Usage <ConfigurationElementType(GetType(CustomFormatterData))> _ Public Class MyFormatter: Implements ILogFormatter
Add a constructor that has parameter of type NameValueCollection.
public MyFormatter (NameValueCollection attributes) { }
'Usage Public Sub New(ByVal attributes As NameValueCollection) End Sub
Add the Format method to your class, and then implement the required behavior.
public string Format(LogEntry log) { }
'Usage Public Function Format(ByVal log As LogEntry) As String End Function
For more details about how to extend the Logging Application Block, with an example that shows how to create a custom event sink, see Creating a Custom Trace Listener.
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. |