RE: Programmatically setting the logger level

Nicko Cadell <[email protected]> Mon, 19 Jan 2004 14:32:20 -0000
Newsgroups gmane.comp.windows.dotnet.log4net.user
Message-ID <[email protected]>
Kevin,

Only the BufferingAppenderSkeleton classes support the Evaluator (i.e. the
ADONetAppender, BufferingForwardingAppender, RemotingAppender, SMTPAppender
and SmtpPickupDirAppender appenders).

If what you want is to set the event threshold for the appender then you do
not need to use the Evaluator at all. i.e. the following configuration would
work:

<appender>
  <param name="Threshold" value="WARN" />
</appender>

Or the equivalent:

<appender>
  <threshold value="WARN" />
</appender>

To set this in code you would use:

fileAppender.Threshold =
log4net.LogManager.GetLoggerRepository().LevelMap["WARN"];

Hope this helps,

Nicko

> -----Original Message-----
> From: Kevin Wittmer [mailto:[email protected]] 
> Sent: 16 January 2004 23:56
> To: [email protected]
> Subject: [Log4net-users] Programmatically setting the logger level
> 
> 
> 
> Hello,
> 
> I am hoping that someone can rattle off a couple of lines of 
> code that would 
> show me how to programmatically set the logger level.
> 
> If I want to accomplish the following:
> 
> <appender>
> 	<evaluator type="log4net.spi.LevelEvaluator">
> 		<param name="Threshold" value="WARN"/>
> 	</evaluator>
> </appender>
> 
> In C# using the various log4net interface and classes, etc. 
> How can this be 
> done?
> 
> My application currently includes the following:
> 
> 	log4net.Appender.RollingFileAppender fileAppender =
> 		new log4net.Appender.RollingFileAppender(
> 		new log4net.Layout.PatternLayout(
> 		"%d [%t] %-5p %c - %m%n"), log4netFile);
> 	fileAppender.MaxFileSize = 65536;
> 	fileAppender.MaxSizeRollBackups = 3;
> 	log4net.Config.BasicConfigurator.Configure(fileAppender);
> 
> Thanks! Maybe we could use the reply(s) from this posting to 
> update the 
> log4net documentation to include such an example. Or, maybe 
> the solution to 
> this could make its way into the log4net FAQ.
> 
> Kevin
> 
> _________________________________________________________________
> Get a FREE online virus check for your PC here, from McAfee. 
> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> 
> 
> 
> -------------------------------------------------------
> The SF.Net email is sponsored by EclipseCon 2004
> Premiere Conference on Open Tools Development and Integration 
> See the breadth of Eclipse activity. February 3-5 in Anaheim, 
> CA. http://www.eclipsecon.org/osdn 
> _______________________________________________
> Log4net-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/log4net-users
> 


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn