How to disable messages for category based on severity in EnterpriseLibrary logging configuration

Microsoft documentation article Source Schema for the Logging Application Block is very hard to follow,the set of articles http://www.education.vic.gov.au/devreskit/appdev/Application%20Blocks/Logging/logging-standards-details.htm#config3 is much better


Finally I found Log Event to Listener Routing in Enterprise Library   article, that very clear described available options , how to disable/enable logging

There are three Filters provided out of the box including a LogEnabledFilter which is a very effective way of short-circuiting the processing of all events, if you want logging turned off entirely. There’s also a CategoryFilter and PriorityFilter provided, but it’s easy enough to write your own.


In the example configuration
<categorySources>
<add switchValue=”Critical name=”MyCategory”>
<listeners>
<add name=”EventLogTraceListener” />
</listeners>
</add>
I can specify switchValue   to Critical to ignore not important messages

From http://www.education.vic.gov.au/devreskit/appdev/Application%20Blocks/Logging/logging-standards-details.htm#config3
The following switchValue settings can be used:

  • Activity Tracing. Allows the Stop, Start, Suspend, Transfer, and Resume events through.
  • All. Allows all events through.
  • Critical. Allows only Critical events through. A critical event is a fatal error or application crash.
  • Error. Allows Critical and Error events through. An Error event is a recoverable error.
  • Information. Allows Critical, Error, Warning, and Information events through. An information event is an informational message.
  • Off. Does not allow any events through.
  • Verbose. Allows Critical, Error, Warning, Information, and Verbose events through. A Verbose event is a debugging trace.
  • Warning. Allows Critical, Error, and Warning events through. A Warning event is a non-critical problem.


The article  Log Event to Listener Routing in Enterprise Library  also describes notProcessed  special source.

  • notProcessed – any event not picked up by the other sources because there was no matching category will be redirected to this source (if any listeners are specified). Note that notProcessed events do not include filtered events (LogFilters) or events that matched a category but weren’t processed due to the switchValue/severity.

Note that most of examples in the Internet do not specify listener element as a child of notProcessed element, but it’s critical to ensure that some categories are not missed completely.
<notProcessed switchValue=”All” name=”Unprocessed Category”>
<listeners>
<add name=”MailListener” />
</listeners>
</notProcessed>

A StackOverflow answer pointed me to the ShouldLog method of LogWriter and  Walkthrough: Checking Filter Status Before Constructing Log Messages:

If you want to check configuraton settings from the code, see
http://stackoverflow.com/questions/3485438/programmatically-access-enterprise-library-logging-configuration-object-model

Consider to create a facade class to the Logging Block as suggested in the answer to pattern for logging using enterprise library

My related previous post: Logging application block-how configure different listeners for different level of message.

Advertisements