Log4Net: Debug vs Info?

In Log4Net, what is the difference between the debugging method and the Info method? Usually, when should I use one over the other?

Example:

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 debugging method in 1,2,3,4 position?

+6
source share
2 answers

This is due to the ability to filter certain information.

The difference is that you can configure your system to record informational messages only and ignore debug messages, or you can configure both to register, and most importantly, you can do this without recompiling / modifying your program.

Even if all messages are recorded, if you use the viewer, you can set the viewer to debug messages and display only higher levels (and therefore more important messages).

(Note: There are actually more levels of logging, such as Warn, Error, and Fatal)

I would like to use the information for the message, which should give me an idea of ​​what the program is doing (and confirm that it works fine) and debug the information that I may need to try to track why it is not working

For example, I have a service that runs on a server that periodically downloads a text file from an external server and then processes the information. I have a program configured only to log informational messages, and I use log.info to record when services start and stop, as well as several other important messages. This makes the log file small, but allows me to see the information I want to use every day.

However, if something goes wrong with the processing, I may need to find out more (I dare say debugging) information about the contents of the file being processed and other information to indicate what it does with the file.

I don’t need and do not want to write this information all the time, therefore, 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 very large and therefore slows down the process).

+10
source

you should use debug if you need this information for debugging only ;-)
information that helps you develop and improve code ... variable values, for example ..

use information , for example, at the production level. maybe some general information, for example, "customer saved"

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

+1
source

Source: https://habr.com/ru/post/893107/


All Articles