How to customize source level of trace listener

Topics: Logging Application Block
Sep 3, 2007 at 2:49 PM
I have a question about the logging application block.

Here is the situation.
In my application I have to log each step of the process : ProcessStep1, ProcessStep2, ...
For each step, I would like to create a Log Category and use different kind of actions like sending email, console printing within the category
Hence, I will have a config file like that:

Category Sources
-- UI Category
---- Email TraceListener (1)
---- Console TraceListener (2)
-- Data Access Category
---- Console TraceListener (3)

In that case, I can manage the logging level in ProcessStep1 or 2 by changing the SourceLevels property. But I would like to have the opportunity to specify the source level for each trace listener, that way I would be able to decide when to log to a specified trace listener from the severity of the log.

In the previous example, I would like to be able to send an email only for message starting at Warning level, but display any kind of level in the Console Tracelistener.

So my question is : is there any way to do it ?
I had the idea to make a CustomTraceListener and add a property like SourceLevels into the properties window, but I didn't find how to do this.
Sep 3, 2007 at 3:07 PM

TraceListeners do have filters (see, including a EventTypeFilter which seems to address your scenario. However these filters are not configurable through EntLib's configuration, and some of the TraceListeners do not consider this parameter.

This can certainly be done, but the solution depends on the amount of effort you want to spend. You could add proper per-listener filter support, by updating the TraceListenerData to have a "Filter" element and create and attach filters based on this configuration, or you could add some kind of "wrapper" trace listener that would filter requests based on a level value configured to it. I don't know the exact details for these changes, as I haven't tried them out, so there might be issues to resolve (I'm thinking about the caching for TraceListeners becoming a cause for some headaches).