I'm currently migrating from log4net as a logging framework to the System.Diagnostics
namespace in order to use 1) a .net built-in framework already available and b) use it's powerful features like activity tracing.
With log4net, I'm used to request the loggers on a class-based way e.g.
private readonly ILog Logger = LogManager.GetLogger(typeof(MyClass).Name);
However with the TraceSource
, it seems like you have to configure each trace source manually in app.config in order to use it. Isn't there a way to create some shared listeners and just use them, with 'global filters' for the TraceEventType
etc. (e.g. EventLogListener
handles Warning/Error, when property "XY" is set, a console listener is active, else log to file etc.)
Here is a sample. You can set up shared listeners. So a given listener only need be configured once. (You still have to map listeners to sources over and over)
The sources can use named switches, and those should be sharable (i.e. two sources use the same switch).
In your question you use the word "filter" which roughly corresponds to a switch value. Filters exist in Systems.Diagnostics trace too, but they are objects that reduce the amount of things a listener responds to based on a variety of criteria, not just the switch value.