开发者

Log4Net : Debug vs Info?

In Log4Net, What is the difference between Debug method and Info method ? Generally when should i use one over the other ?

Ex :

try

{

 // updating the customer object

 log.Info ("before loadi开发者_Python百科ng current customer");     //1
 Customer objCustomer=GetCurrentLoggedInCustomer();
 log.Info ("Current customer loaded ");  //2
 objCustomer.LastName="New name";
 log.Info("Before saving");   //3
 objCustomer.Save(); 
 log.Info("Saved");     //4

}
catch(Exception ex)
{
    log.Error(ex.Message);  //5
}

Should i use Debug method in 1,2,3,4 positions ?


It is to do with the ability to filter out certain information.

The difference is that you can configure your system to log only info messages and ignore debug messages, or you can configure to log both, and most importantly, you can do this without recompiling/changing your program.

Even if the all messages are recorded, if you are using a viewer, then you can set the viewer to filter out debug messages and only show the higher levels (and hence more important messages)

(Note, There are actually more logging levels, eg, Warn, Error and Fatal)

I would tend to use info for message which are to give me an idea of what the program is doing (and to confirm that it is working ok) and debug for the sort of information I might need to try to track down why it isn't working

For example, I have a service which runs on a server which periodically downloads a text file from an external server and then processes the information. I have the program configured to just log info messages and I use log.info to record when the services starts and stops and a few other important messages. This makes the log file small yet enables me to see the information I want in every day use.

However, if ever anything goes wrong with the processing, I might need to see more (dare I say debug) information about the contents of the file I am processing and other information to indicate what it is doing with the file.

I don't need and don't want to record this information all the time, so by using log.debug, I can ignore it until the time comes when I need it. (The reason I don't want to record it is because the output is extremely large and hence slows the process down).


you should use debug if you need this information just for debugging ;-)
information which helps you to develop and improve the code... values of variables for example..

use info for example in production level. maybe some general information like "customer saved"

but be careful not to use too many logs, as it can slow down your application in worst case

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜