Is there a way to set the log level in log4net programmatically? I\'d assumed that there would be a property that would let you do this, but I can\'t seem to find one.
This is the way I'm configuring log4net programmatically:
//declared as a class variable
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
PatternLayout layout = new PatternLayout(@"%date %-5level %message%newline");
RollingFileAppender appender = new RollingFileAppender();
appender.Layout = layout;
appender.File = "c:\log.txt";
appender.AppendToFile = true;
appender.MaximumFileSize = "1MB";
appender.MaxSizeRollBackups = 0; //no backup files
appender.Threshold = Level.Error;
appender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(appender);
I think the Appender's Threshold property is what you looking for, it will control what levels of logging the appender will output.
The log4net manual has lots of good configuration examples.