1

I'm working on a project that is using a custom trace listener:

<system.diagnostics>
<trace>
  <listeners>
    <add name="CustomTraceListener" type="CustomTraceListener, CustomTraceListener" />
  </listeners>
</trace>
</system.diagnostics>

And I have a class that logs way too much:

namespace MyApp.SuperChatty{
   //I log too much
   public class HeavyLogger{
   }
}

How can I suppress Verbose messages from MyApp.SuperChatty.HeavyLogger?

When I used log4net, I could create a specific logger for a given class or namespace (log4net: Configure to ignore messages from a specific class), so how can I do this with Tracing?

Community
  • 1
  • 1
Philip Pittle
  • 11,821
  • 8
  • 59
  • 123

1 Answers1

2

The best solution I can think of is to create a custom TraceFilter (TraceFilter at MSDN). I've never done this myself, but I would expect that you could then provide a namespace/partial namespace to InitializeData and then determine whether or not to trace from a source in the ShouldTrace method.

Adam Prescott
  • 943
  • 1
  • 8
  • 20