Log4net/日志记录-您发现什么有用? [英] Log4net/Logging - What have you found to be useful?

查看:57
本文介绍了Log4net/日志记录-您发现什么有用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Log4Net,并希望了解您发现对日志记录记录有用的内容.

I just started using Log4Net and was looking to see what you have found to be useful in your logging experiences.

您发现什么类型的东西对记录很有用;最终只是噪音;什么时候使用不同的日志记录级别(DEBUG,INFO等);每个日志条目都有标准格式吗?您是否总是有记录?

What types of things have you found to be useful to log; what ended up being just noise; when do you use the different logging levels (DEBUG, INFO, etc); do you have a standard format for each log entry; are there things you ALWAYS log?

有什么陷阱吗?一般而言,关于日志记录的好文章?

Any pitfalls? Good articles on logging in general?

更新:您登录到哪里?什么叫Appender,为什么?

Update: Where do you log to? What Appenders and why?

谢谢!

推荐答案

我的回答基于罗伯特·科扎克(Robert Kozak)的出色回答,尽管我不太喜欢以相同的方式使用日志记录

I'm basing my response on the excellent response of Robert Kozak, even though I don't quite use my logging the same way

我使用五种类型的日志语句:

I use five types of log statements:

  • 调试
  • 信息
  • 警告
  • 错误
  • 致命
  • DEBUG
  • INFO
  • WARNING
  • ERROR
  • FATAL

DEBUG 语句是在仍在编写应用程序以及需要完全了解执行流的位置/位置时非常有用的语句.您可以使用DEBUG语句来测量锁前的队列,也可以检查登录用户的用户名,甚至可以查看正在困扰的某个SQL调用的参数. DEBUG用于通常不需要知道的语句.

DEBUG statements are statements which are useful when you are still writing an application, and when you need a complete understanding of what/where your execution flow is. You can use DEBUG statements to measure the queue in front of a lock, or check usernames of users logging in, or even the parameters for a certain SQL call that's been troubling. DEBUG is for statements which are not generally needed to be known.

信息应该在有信息的情况下使用,如果出现问题,该信息将非常有用,但并不表示有任何问题.如果您使用太多的INFO语句,您的日志将变得and肿且无用,因此请当心. 使用INFO来获取错误时所需的任何关键信息,而且离错误将要发生的地方也不远.

INFO should be used whenever there is information which will be very useful if something goes wrong, but does not indicate that anything has gone wrong. If you use too many INFO statements, your logs will become bloated and unuseful, so be careful. Use INFO for any critical information which you will need on error, and it is no where near where the error will be throw.

如果您检测到可恢复但仍然出乎意料的话,请使用 WARN 级别(至少有些期望,因为您抓住了它).它表明您的应用程序可能处于无法使用的状态,但是您认为您可以在当前执行路径上恢复/继续.

Use WARN level if you have detected a recoverable, but still unexpected (at least a little expected, because you caught it). It indicates that your application MAY be in an unworkable state, but that you believe you can recover/continue on the current execution path.

错误警告用于在您遇到意外异常时发出的警告.如果要恢复/重试当前方法,建议您使用WARN.如果要取消/保释,请使用ERROR.即使您的程序可以继续运行,ERROR也意味着您正在尝试做某事而被拒绝,因此您将继续进行其他事情.

ERROR warnings are for whenever you catch an unexpected exception. If you are recovering/retrying the current method, I'd suggest using WARN. If you are canceling/bailing out, use the ERROR. Even if your program can continue, ERROR means that you were attempting to do something and were rejected, and are therefore moving on to other things.

FATAL 用于当您在远低于投掷物的水平上抓到某物时,而您基本上不知道发生了什么.这意味着您甚至没有尝试继续执行,您只是要记录所有可能的信息,然后尝试正常退出. 致命错误很少使用,因为通常如果您发现错误,则您有足够的信息来尝试并继续执行.但是,如果尝试继续操作,可能会发生损坏,请记录致命错误,然后再逃之away.

FATAL is for use when you catch something at a level far beneath where it was thrown, and you essentially have no idea what's going on. It means you are not even attempting to continue execution, you are simply going to log every possible bit of information at your disposal and then try to exit gracefully. FATAL errors are infrequently used because generally if you catch an error, you have enough information to try and continue execution. But in the scenarios where corruption might occur if you try and continue, log a FATAL error, and then run away.

关于您要登录的位置.我通常喜欢登录到我的应用程序服务器上的共享"文件夹(请谨慎对待权限,以便它们不公开),以便可以轻松访问日志,并且它们始终是我调试的第一步. 如果可能,请进行设置,以便通过电子邮件发送任何警告,错误或致命错误,以便您获得高级"警告.

As for where you're logging to. I usually like to log to a 'shared' folder on my app servers (be careful about permissioning so that they are not public) so that the logs are very easily accessible and they are always my first step for debugging. If possible, set it up so that any errors that are WARNING, ERROR, or FATAL are sent out by email so that you'll have 'advanced' warning.

欢呼

这篇关于Log4net/日志记录-您发现什么有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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