Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Specifying log level at runtime
Prev Next
You are not authorized to post a reply.

Author Messages
Rennie Petersen

06/27/2008 10:42 PM  

This may be obvious, but I've missed it. (And I did try searching the mailing list archives too.)

Is there any simple way to specify the level of a logging in a C# program at runtime? The logger exposes methods log.Debug, log.Error, etc., but if I have the level passed into a function as a log4net.Core.Level value, is there any way other than using a switch statement and 5 log.xxx statements to get the results I want?

Thanks.

Walden H. Leverich

06/27/2008 11:17 PM  

Something along these lines?

 

log.Logger.Log(this.GetType(), log4net.Core.Level.Critical, "The message", theException);

 

where log is the “normal” class-level logger:

 

static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

 

-Walden

 

--

Walden H Leverich III
Tech Software
(516) 627-3800 x3051

WaldenL@TechSoftInc.com
http://www.TechSoftInc.com

Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)

Rennie Petersen

06/27/2008 11:39 PM  
Hi Walden,
 
Thanks - that looks like it's what I was hoping for (although a bit more convoluted than I'd prefer :-)
 
One further question. For the situations where there is no exception, is it OK to use null for the fourth argument?
 
(There apparently is no overload that omits that fourth argument.)
 
Thanks again.
 
Rennie
 
Walden H. Leverich

06/27/2008 11:51 PM  

> For the situations where there is no exception, is it OK to use null for the fourth argument?

 

I’m not positive, but I believe so.

 

--

Walden H Leverich III
Tech Software
(516) 627-3800 x3051

WaldenL@TechSoftInc.com
http://www.TechSoftInc.com

Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)

 

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Specifying log level at runtime



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement