You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Rennie Petersen <rp...@merlinia.com> on 2008/06/27 22:42:38 UTC
Specifying log level at runtime
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.
RE: Specifying log level at runtime
Posted by "Walden H. Leverich" <Wa...@TechSoftInc.com>.
> 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
<BLOCKED::blocked::http://www.techsoftinc.com/>
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)
From: Rennie Petersen [mailto:rp@merlinia.com]
Sent: Friday, June 27, 2008 5:39 PM
To: Log4NET User
Subject: RE: Specifying log level at runtime
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
________________________________
From: Walden H. Leverich [mailto:WaldenL@TechSoftInc.com]
Sent: 27. juni 2008 23:18
To: Log4NET User
Subject: RE: Specifying log level at runtime
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.GetCurrentMeth
od().DeclaringType);
-Walden
--
Walden H Leverich III
Tech Software
(516) 627-3800 x3051
WaldenL@TechSoftInc.com
http://www.TechSoftInc.com
<BLOCKED::blocked::http://www.techsoftinc.com/>
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)
RE: Specifying log level at runtime
Posted by Rennie Petersen <rp...@merlinia.com>.
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
________________________________
From: Walden H. Leverich [mailto:WaldenL@TechSoftInc.com]
Sent: 27. juni 2008 23:18
To: Log4NET User
Subject: RE: Specifying log level at runtime
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.GetCurrentMeth
od().DeclaringType);
-Walden
--
Walden H Leverich III
Tech Software
(516) 627-3800 x3051
WaldenL@TechSoftInc.com
http://www.TechSoftInc.com
<BLOCKED::blocked::http://www.techsoftinc.com/>
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)
RE: Specifying log level at runtime
Posted by "Walden H. Leverich" <Wa...@TechSoftInc.com>.
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.GetCurrentMeth
od().DeclaringType);
-Walden
--
Walden H Leverich III
Tech Software
(516) 627-3800 x3051
WaldenL@TechSoftInc.com
http://www.TechSoftInc.com
<BLOCKED::blocked::http://www.techsoftinc.com/>
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)