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.
| 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. |
|
|
|
ActiveForums 3.7
|