I've been working on a library in C# and would like to offer capability for it automatically log all exceptions. Ideally, I'd like it to use log4net, thus allowing the client to configure the log however they like (i.e. they can redirect it to the EventLog or a database or what have you).
However, I would like to avoid having the logging dependency if they chose not to use the logging feature. Is this doable?
In other words, is there a way I can optionally have a log4net dependency, depending on what the client sets in config file?
The obvious answer is to use the System.Diagnostics.Trace
subsystem with a custom TraceSource
. That way you can set up, in the configuration file, any TraceListener
you'd like, including log4net, EventLog, text files, Console
, or XML files.
If you added a log4net TraceListener
then the dependency would be loaded at runtime, and not compiled in. The Trace
subsystem has become quite powerful since its inception, and I recommend you look into it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With