Compartilhar via


Extending the Semantic Logging Application Block

patterns & practices Developer Center

The Semantic Logging Application Block is designed to suit a variety of application scenarios, and to provide the most commonly used logging functions. However, you can extend the application block through designated extension points in order to meet your specific requirements.

Typically, these extensions 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 incorporate your extensions by instantiating them in code or by using the available configuration settings.

The main options for extending the Semantic Logging Application Block are:

  • Creating custom event filters. The sink classes included with the Semantic Logging Application Block implement the IObserver interface, which enables them to subscribe to event listeners that implement the IObservable interface. By creating custom code that subscribes to an IObservable instance and that generates a new stream that an IObserver instance can subscribe to, you can manipulate the events before they are seen by the sink. For more information, see Creating a custom event filter.
  • Creating custom event formatters. The Semantic Logging Application Block includes three text formatters that format the log messages written to log stores: EventTextFormatter, JsonTextFormatter, and XmlTextFormatter. If you need to generate a specific format for your log messages, you can create a new formatter that generates output in exactly the format you require. For an information, see Creating a custom event formatter.
  • Creating custom event sinks. The Semantic Logging Application Block includes a number of sinks for receiving and processing log messages such as the SqlDatabaseSink and the RollingFlatFileSink. You can create a sink that stores log messages in other locations, or takes specific actions based on the contents of log messages. For example, you can create a sink that sends email warnings to an administrator in response to specific events and combinations of events. For more information, see Creating a custom event sink.
  • Creating custom event listener hosts. The Semantic Logging Application Block includes the Out-of-Process Host event listener application you can use in the out-of-process scenario to collect trace messages from your applications. The host application can run as a console application or as a Windows service, and should satisfy the vast majority of scenarios. However, you can create your own custom out-of-process event listener host. For more information, see Creating a custom out-of-process event listener host application.

Next Topic | Previous Topic | Home | Community