Brian Sherwin's Blog

Moving at the Speed of .Net
posts - 98, comments - 62, trackbacks - 30

My Links

News

Twitter












Tag Cloud

Archives

Links

When to check IsDebugEnabled when using log4net

I see this a lot in projects that I have been involved in where the code goes something like this:

if (log.IsDebugEnabled)

log.Debug ("Connecting to Database");

conn.Open();

or something similar when calling the other logging methods (Warn/IsWarnEnabled, Error/IsErrorEnabled, etc)

Here's the point of this short post...you only need to check the log setting if what you about to do is time consuming.  For example, if you are going to walk through a collection of objects and get a list of ID's that you are about to process and you want to output that to your log, check the flag.

Checking the flag before you do something short and piddly...waste of time. Look at the log4net code. You'll notice that the methods will check the flags for you.

Technorati Tags: ,
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Tuesday, July 15, 2008 10:43 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: