Jaa


Logging to WMI

This scenario is one of several that describe the typical requirements when using the Logging Application Block in your applications. It describes the process for setting up the block to send log events to the Windows Management Instrumentation database. The process just involves configuring the block—there are no other tasks required to prepare your application. This topic acts as a quick reference to help you quickly set up the Logging Application Block to perform the required logging action.

Typical Goals

You need to send logging information created as log entries to one or more sinks or targets, and the list of targets includes Windows Management Instrumentation. You want to set up the Logging Application Block to use a suitable trace listener, and configure the options you require.

Solution

The high-level stages of the process that you should follow are:

  • Configure your application to use the Logging Application Block with a WMI trace listener.
  • Configure the properties of the WMI trace listener.
  • Configure the required filters and log sources for the Logging Application Block.
  • Add references to the Logging Application Block to your application and write code to send log entries to the block.

The following steps describe the whole process in more detail.

To configure logging to WMI

  1. Add the Logging Application Block to your application configuration, and then add a WMI trace listener to the block configuration as shown in the topic Configuring Trace Listeners.
  2. Set the Severity Filter property of the WMI trace listener to specify the level of messages that will be logged. The valid values are All (the default), Off, Critical, Error, Warning, Information, Verbose, and ActivityTracing. The setting effectively means "the specified level and everything more important." For example, the Warning setting will detect warnings, errors, and critical events. For more information about configuring the WMI trace listener, see the table of properties and descriptions in the topic Trace Listener Properties.
  3. Specify the required settings for the Trace Output Options property of the WMI trace listener. This allows you to include a range of information in the log entry, such as the date and time, the call stack, and the process ID. For more information about setting the Trace Output Options property of the WMI trace listener, see the table of possible values and descriptions in the topic TraceOutputOptions Values.
  4. Configure any trace sources you require. In general, you will add additional categories if you want to be able to assign log entries to more than the default General category. You may also want to change the settings for the Logging Errors & Warnings, Unprocessed Category, and All Events special trace sources. For example, you may want to send entries for logging errors to the Windows Event Log or a disk file. For more information on configuring trace sources, see the topic Configuring Trace Source Categories.
  5. Configure any log filters you require. You may want to filter log entries arriving at the Logging Application Block by category or by priority, or completely enable or disable logging. For more information on configuring log filters, see the topic Configuring Logging Filters.
  6. Add references to the Logging Application Block and other required assemblies to your application. For more details, see Adding Application Code.
  7. Write code to create log entries and send them to the Logging Application Block. For more information, see the topic Populating and Raising Events from Code and Populating a Log Message with Additional Context Information.