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.Tracesubsystem with a customTraceSource. That way you can set up, in the configuration file, anyTraceListeneryou’d like, including log4net, EventLog, text files,Console, or XML files.If you added a log4net
TraceListenerthen the dependency would be loaded at runtime, and not compiled in. TheTracesubsystem has become quite powerful since its inception, and I recommend you look into it.