Logging: Separate Trace Listeners based on Priority?

Topics: Logging Application Block
Aug 6, 2008 at 6:16 PM
I'd like to set up two trace listeners, one for trace messages and one for more critical information. The trace messages should go to a trace.log file and the critical messages should be emailed to me.

I can see how to easily set up the trace listeners, but not how to filter the correct messages to each. I can create a Priority Filter, but there doesn't seem to be a way to assign it to a specific trace listener. Can someone please help me out here? I'm just stuck.

Thanks,

Brian
Aug 6, 2008 at 6:58 PM

Hi,

If you're using EntLib v4, you can assign different filters to each trace listener as indicated in http://msdn.microsoft.com/en-us/library/cc511699.aspx#trace_flatfile. These settings configure the standard TraceListener.Filter property, and you're restricted to filter Severity. Additionally, there's an error in the way the Formatted Event Log trace listener handles the filter, so if you need to log to the event log you'll need to use the standard System.Diagnostics.EventLogTraceListener.

Cheers,
Fernando

Aug 6, 2008 at 7:26 PM
Fernando,

Thanks for the reply. I am using v4. If I understand you correctly, I cannot assign a PriorityFilter to a specific TraceListener, but rather just a SeverityFilter. This seems limiting, but I'll go ahead and work around it for now.