要我在web应用程序可以记录哪些信息? [英] What information should I be logging in my web app?

查看:123
本文介绍了要我在web应用程序可以记录哪些信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整理了一个Web应用程序,我试图执行一些日志记录。我从来没有见过的东西记录任何很好的例子。难道仅仅是例外?是否有其他的事情我应该记录?你发现了什么类型的信息查找和修复bug非常有用。

I finishing up a web application and I'm trying to implement some logging. I've never seen any good examples of what to log. Is it just exceptions? Are there other things I should be logging? What type of information do you find useful for finding and fixing bugs.

寻找一些具体的指导和最佳做法。

Looking for some specific guidance and best practices.

感谢

跟进

如果我登录专门的例外,我应该记录什么信息?我应该做得比 _log.Error(ex.Message,除息)更多的东西;

If I'm logging exceptions what information specifically should I be logging? Should I be doing something more than _log.Error(ex.Message, ex); ?

推荐答案

下面是我能做什么和应用程序,你为什么会想和你怎么可能去这样做内记录的逻辑分解。不管是什么,我会建议实现在使用日志框架,例如log4net的。

Here is my logical breakdown of what can be logged within and application, why you might want to and how you might go about doing it. No matter what I would recommend using a logging framework such as log4net when implementing.

当一切已经失败,这不应该。它是具有捕捉所有unhanded例外的中央装置是个好主意。这是不应该
更难那么除非你使用比多线程在一个巨大的try / catch包裹整个应用程序。这项工作并没有到此结束
虽然因为如果等到例外达到你很多有用的信息会超出范围。至少,你应该
尽量收集应用程序状态的特定部分有可能帮助调试为堆栈开卷。您的应用程序应该总是ppared生产这种类型的日志输出,特别是在生产$ P $。确保如果你还没有准备好要看看 ELMAH 。我还没有尝试过,但我有<一个href=\"http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx\">heard伟大的事情

When everything else has failed, this should not. It is a good idea to have a central means of capturing all unhanded exceptions. This shouldn't be much harder then wrapping your entire application in a giant try/catch unless you are using more than on thread. The work doesn't end here though because if you wait until the exception reaches you a lot of useful information would have gone out of scope. At the very least you should try to collect specific pieces of the application state that are likely to help with debugging as the stack unwinds. Your application should always be prepared to produce this type of log output, especially in production. Make sure to take a look at ELMAH if you haven't already. I haven't tried it but I have heard great things

我称之为应用程序日志包括捕获有关你的应用程序在概念层面,如做信息的任何记录已删除订单或A用户签约。这种信息可以在趋势分析,审计等制度,锁定下来,测试,安全和检测粗的错误非常有用。这可能是为计划在生产中在离开这些日志以及,也许粒度不同水平是一个好主意。

What I call application logs includes any log that captures information about what your application is doing on a conceptual level such as "Deleted Order" or "A User Signed On". This kind of information can be useful in analyzing trends, auditing the system, locking it down, testing, security and detecting bugs of coarse. It is probably a good idea to plan on leaving these logs on in production as well, perhaps at variable levels of granularity.

跟踪记录,对我来说,重新presents记录的最颗粒状。在这个层面上,你关注较少有关应用程序在做什么,更多的它是如何做的。这是一步以上通过线code线实际上走。这可能是在处理并发性问题或任何与此有关的是难以重现最有帮助。你不会希望总是有这样的运行,大概只有在需要的时候将其打开。

Trace logging, to me, represents the most granular form of logging. At this level you focus less on what the application is doing and more on how it is doing it. This is one step above actually walking through the code line by line. It is probably most helpful in dealing with concurrency issues or anything for that matter which is hard to reproduce. You wouldn't want to always have this running, probably only turning it on when needed.

最后,与通常只能得到在最后解决许多其他的事情,最好的时间去思考记录是在项目的开始,使应用程序可以用它来设计的初衷。大的问题,但!

Lastly, as with so many other things that usually only get addressed at the very end, the best time to think about logging is at the beginning of a project so that the application can be designed with it in mind. Great question though!

这篇关于要我在web应用程序可以记录哪些信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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