views:

64

answers:

1

How do I go about using filtering on the built in trace listeners, such as System.Diagnostics.DefaultTraceListener and System.Diagnostics.TextWriterTraceListener?

I don't want to have to override write methods and explicitly check the filtering, but I can find no way to attach a level to trace information?

+1  A: 

You can do some filtering using trace switches. Add a trace switch to your config file then set the level to 0, 1, 2, 3 or 4 (for, respectively off, error, warning, info, verbose). You would then use the WriteLineIf(traceSwitch.Error, ....) to only print if the traceswitch is configured for errors, WriteLineIF(traceSwitch.Warning, ...) to print if the trace switch is set to errors or warnings, etc...

Arnshea
Ah, so simple. Thanks @Arnshea!
ProfK