在一个应用程序中要登录多少日志,多少日志太多? [英] How much to log within an application and how much is too much?

查看:78
本文介绍了在一个应用程序中要登录多少日志,多少日志太多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道有多少人登录他们的应用程序?

Just wondering how much people log within their applications???

我已经看到了:

我通常喜欢使用错误日志 级别记录任何异常 被应用程序捕获.我会用 INFO日志级别为第一级" 每当我显示的调试方案 输入或退出方法.从那里我 使用DEBUG日志级别进行跟踪 详细资料.致命日志 级别用于任何以下情况的例外情况: 我未能赶上我的基于Web的网站 应用程序."

"I typically like to use the ERROR log level to log any exceptions that are caught by the application. I will use the INFO log level as a "first level" debugging scheme to show whenever I enter or exit a method. From there I use the DEBUG log level to trace detailed information. The FATAL log level is used for any exceptions that I have failed to catch in my web based applications."

其中包含以下代码示例:

Which had this code sample with it:

Public Class LogSample

   Private Shared ReadOnly Log As log4net.ILog = log4net.LogManager.GetLogger(GetType(LogSample))

   Public Function AddNumbers(ByVal Number1 As Integer, ByVal Number2 As Integer) As Integer

      Dim intResults As Integer

      Log.Info("Starting AddNumbers Method...")
      Log.Debug("Number1 Specified: " & Number1)
      Log.Debug("Number2 Specified: " & Number2)

      intResults = Number1 + Number2

      Try

         intResults = Number1 + Number2

      Catch ex As Exception

         Log.Error("Error Adding Nubmers.", ex)

      End Try

      Log.Info("AddNumbers Method Complete.")

      Return intResults

   End Function

End Class 

但是这似乎给方法增加了很多.例如,通常可能是7行代码的类突然变成12行代码.该方法还失去了一些清晰度和简单性.

But this just seems to add so much to the method. For instance a class that would normally be maybe 7 lines of code suddenly becomes 12 lines of code. The method also loses some of its clarity and simplicity.

但是可以说,进行日志记录的好处可能是不错的.例如,在生产系统中进行性能监视,追查生产中的异常错误(不是要始终保持所有日志记录处于打开状态.

But in saying that the benefit of having the logging in place can be good. For instance performance monitoring in a production system, chasing down aberrant bugs in production (not that you would have all this logging turned on all the time.

因此,我想知道人们在做什么? 干杯 安东尼

Hence I am wondering what people do? Cheers Anthony

推荐答案

...嘿,我是否获得了在SO问题中被引用为主题的标志? 8 ^ D

...hey, do I get a badge for being quoted as the topic in a SO question? 8^D

但是,认真地说,关于上述日志记录注释,我想澄清的一件事是,我对详细"日志记录进行辩护的部分原因是基于我利用了log4net本身的功能这一事实.

But seriously though, one thing I want to clarify about the logging comment above is that part of my justification for the "verbose" logging is based on the fact that I'm leveraging the features of log4net itself.

在我提供的示例中,该方法每天以WARN模式记录.这意味着唯一会默认"记录的是发生异常.如果我从一位客户那里接到有关应用程序错误的电话,那么他们不必在屏幕上阅读一些隐秘的消息,我便跳入日志并可以查看发生了什么.大多数时候,答案就在那里.

In the sample I provided, that method logs on a daily basis in WARN mode. Which means that the only thing that gets logged "by default" is if an exception occurs. If I get a call from one of my clients about having an error in the application, they don't have to read me some cryptic message on the screen, I jump in the log and can see what's going on. Most of the time, the answer is right there.

如果答案不容易得到怎么办? Log4net允许我更新配置文件(无需重新编译,无需获得sysadmin批准即可访问Web服务器上的某些特殊系统文件)并进入INFO模式.现在,您开始看到第二层日志记录.也许代码从未将其循环到某个循环.也许数据检索的记录集为空.第二级调试很有用,日志只会稍大一些.完成此操作后,我可以再次更改配置并返回日志记录.

What happens if the answer isn't readily available? Log4net allows me to update my configuration file (no re-compilation necessary, no need to get access to some special system file on the web server with the sysadmin's approval) and go into INFO mode. Now you start seeing a second layer of logging. Maybe the code never made it to a certain loop. Maybe the data retrieval had an empty record set. This second level of debugging is helpful, and the log only gets slightly larger. Once this is done, I can change the config again and go back to the light logging.

自然,如果事情真的很疯狂,那么我进入了完整的调试级别,并且我想知道每个变量在报告什么,我正在处理什么DataRows以及应用程序中正在发生什么.在我当前的工作场所,我们没有能力对Web应用程序进行远程调试,并且我们不能总是在不增加数据潜力的情况下利用生产数据库,因此,进行完整的调试是下一个最好的选择.

Naturally if things are REALLY crazy, then I go to the full debug level, and I want to know what each variable is reporting, what DataRows I'm dealing with, and what is going on in the application. At my current place of work, we don't have the ability to do remote debugging into our web applications, and we can't always tap into the production database without potentially augmenting data, so having this full debug is the next best thing.

我同意大多数人的看法,即过多的日志记录确实会使应用程序崩溃,并引起更多的问题,超出了应有的价值.如果不建议在应用程序中使用这种冗长的日志记录,除非该应用程序出于安全原因对其进行了担保.但是,在我看来,能够在需要时利用冗长的日志记录而不必重新编译我的代码是一个巨大的好处,并且如果您有一个可以轻松实现的框架(例如log4net),那么我说变得好听且冗长,如果您必须返回到代码本身,很容易从心理上过滤掉日志代码引用.

I agree with the majority of folks out there that excessive logging can really bring down an application and cause more problems than it is worth. If wouldn't recommend this kind of verbose logging in an application either unless the application warranted it for security reasons. However, being able to leverage verbose logging when needed and without having to recompile my code IS a HUGE benefit in my opinion and if you have a framework that can allow for it easily (such as log4net), then I say get nice and verbose and it is easy enough to mentally filter out the log code references if you're having to go back into the code itself.

如果我感到防御或咆哮,我深表歉意,无论如何,我不是那个意思.我只是想提供更多背景知识,说明如何以及为什么在上述方法中使用log4net设置日志记录. 8 ^ D

I apologize if I sound defensive or ranting, I don't mean that in any regard. I just wanted to provide a bit more background into how and why I setup my logging using log4net in the method mentioned. 8^D

这篇关于在一个应用程序中要登录多少日志,多少日志太多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆