Log4Net:调试与信息?

发布于 2024-11-25 06:52:28 字数 503 浏览 0 评论 0原文

在Log4Net中,Debug方法和Info方法有什么区别?一般来说,我什么时候应该使用其中一种而不是另一种?

例如:

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
}

我应该在 1、2、3、4 位置使用调试方法吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

是伱的 2024-12-02 06:52:28

它与过滤某些信息的能力有关。

不同之处在于,您可以将系统配置为仅记录信息消息并忽略调试消息,或者您可以配置为记录两者,最重要的是,您可以在不重新编译/更改程序的情况下执行此操作。

即使记录了所有消息,如果您使用查看器,则可以将查看器设置为过滤掉调试消息并仅显示更高级别(因此更重要的消息)

(注意,实际上有更多日志记录级别,例如,警告,错误和致命)

我倾向于使用信息作为消息,这让我了解程序正在做什么(并确认它工作正常)并调试我可能需要尝试的信息找出它不起作用的原因

例如,我有在服务器上运行的服务,定期从外部服务器下载文本文件,然后处理该信息。我将程序配置为仅记录信息消息,并使用 log.info 来记录服务何时启动和停止以及其他一些重要消息。这使得日志文件很小,但使我能够在日常使用中看到我想要的信息。

但是,如果处理过程中出现任何问题,我可能需要查看有关我正在处理的文件内容的更多(我敢说调试)信息以及其他信息以指示它对文件执行的操作。

我不需要也不想一直记录这些信息,因此通过使用 log.debug,我可以忽略它,直到需要时为止。 (我不想记录它的原因是因为输出非常大,因此减慢了过程)。

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

美煞众生 2024-12-02 06:52:28

如果您仅需要此信息进行调试,则应该使用debug;-)
帮助您开发和改进代码的信息...例如变量的值..

例如在生产级别使用 info 。也许是一些一般信息,例如“客户已保存”,

但请注意不要使用太多日志,因为在最坏的情况下它可能会减慢您的应用程序

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文