.NET lets you add trace statements to code. You can use
Trace.WriteLine"(Some message");
and then define a trace listener to collect those messages to a log file. OK so far.
But you can also do:
Trace.WriteLine"(Some message", "Category");
How can you set up a filter in app.config (ie <program>.exe.config) so that only messages with a certain value of “Category” are sent to a listener. The documentation hints that you can do this but falls short of telling you how, I think! I want to define my own categories (by subsystem) and be able to route trace to various log files when needed.
(Yes I know all about log4net and how that can solve all my problems).
You will need to code an implementation of
TraceFilterto filter traces by the category string. Otherwise, you could use theTraceEventmethod and then useEventTypeFilterto filter traces based on theTraceEventType.To modify filters, you use the
app.configfile as described in the example for theEventTypeFilter.