Neil P
Neil P

Reputation: 3210

Can I use log.IsDebugEnabled before a log.Trace?

I am using log4net to log messages from my c# application. I want to know if I can use the following code when logging a trace entry:

if (log.IsDebugEnabled)
     log.Trace("MY trace entry");

I am working on the assumption that if the logging level is set to trace then the debug will always be enabled. As Debug and trace will only be used for troubleshooting, it would be permissible for any debug code to also enter this block.

Upvotes: 0

Views: 312

Answers (1)

sgmoore
sgmoore

Reputation: 16077

It might be possible to use something like a LevelRangeFilter to disable logging at the debug level but leave it enable at the traceLevel, which might cause problems with your method

So why not check for the actual level?

eg

if (log.Logger.IsEnabledFor(log4net.Core.Level.Trace))
    log.Trace("MY trace entry");

Upvotes: 2

Related Questions