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:
log4net,
.net