Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 loading 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 ?

like image 481
Shyju Avatar asked Jul 19 '11 21:07

Shyju


1 Answers

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).

like image 196
sgmoore Avatar answered Sep 21 '22 06:09

sgmoore