I have a console application that is using a log4net setup for logging information to the console output only at the moment.
I have various log.Debug("Debug info")
statements which I only want to print out to the console if a debug flag within my application is set.
The debug variable is set by reading a switch passed to the application when it is invoked. The arguments are read using NDesk.Options
.
I want to avoid wrapping every debug statement in an if:-
bool debug = false;
// read switches
var p = new OptionSet() {
{ "d|debug", "debug mode", v => debug = v != null },
};
if (debug) {
log.Debug("Debug info")
}
Is there anything I can put in the <log4net><appender>
section of the configuration to enable this, or is there a way of overriding log.Debug to provide the logic ?