ProfK
ProfK

Reputation: 51063

Trace Filtering

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?

Upvotes: 0

Views: 285

Answers (1)

Shea
Shea

Reputation: 11243

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...

Upvotes: 1

Related Questions