本文介绍了ASP.NET的Web API日志记录和跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

人一旦到位的ASP.NET Web API使用log4net的日志记录和跟踪设置,哪些是需要被记录和/或跟踪的具体方面?

Once one has a logging and tracing setup using log4net in place for ASP.NET Web API, what are the specific aspects that need to be logged and/or traced?

我是专门从网页API的角度问这个。有一系列的必须登录该必须追查该
就像,信息跟踪有关控制器的要求,任何null检查等。

I am asking this specifically from Web API perspective. Is there a series of MUST Log this or MUST trace this.Like, INFO traces about a controller's request, any NULL checks, etc.

有没有可以针对被验证,以确保在的ASP.NET Web API的最佳记录和跟踪报道的参考列表?

Is there a reference list that can be validated against to ensure optimum logging and tracing coverage in ASP.NET Web API ?

推荐答案

所以我会假设你的目标的日志记录,因为它应该是,来调试应用程序,而不是衡量性能。

So I will assume your goal for the logging is, as it should be, to debug the application rather than measure for performance.

尽管我认为没有一个正确答案,在最小的我总是会尝试登录

While I think there is no one 'right' answer to this, at the minimum I would always try to log

  • 时间戳,类/函数名和线程名称(如果运行年多线程应用程序)在每个日志行

  • Timestamps, class/function names and thread name (if yr running a multithreaded app) in every log line

  • 快速日志行@每一个切入点,用的全部内容一起
        在该请求中传递,pferably $ P $中,将使它的格式
        更容易为你从补发提琴手或类似相同的请求
        工具(这可以通过自定义操作过滤器来完成 - see如何
        笔者使用这些性能监视网页API应用程序这里)

  • 如果你正在做的任何数据库查询作为你的行动,日志的一部分
        如果可能的话(再次充分查询SQL字符串,使其更容易
        调试期间重复),以及至少行#
        返回

  • If you are doing any database queries as part of your action, log the full query sql string if possible (once again to make it easier to repeat during debugging) as well as at least the # of rows returned

  • 如果你正在做的任何外部服务电话,登录既充分
        请求和响应串

  • If you are doing any external service calls, log both the full request and response strings

  • 使用try / catch块记录任何异常(你也可以使用
        有点像ELMAH库自动做到这一点,而
        比处理在code - 在这里和<一个href=\"http://blogs.msdn.com/b/webdev/archive/2012/11/16/capturing-unhandled-exceptions-in-asp-net-web-api-s-with-elmah.aspx?Redirected=true\">here

  • 凡是在运行期间解决 - 想从配置文件,数据库查询,计算值,值也应记录

  • Anything that is resolved during runtime - think values from config files, database queries, calculated values, should also be logged

    我敢肯定有更多的在此列表中 - 后什么年中的应用做这一切变化。你应该问自己在每一步 - 有什么可以去错在我的应用程序?什么事情会我还是可怜的家伙会后我在这找工作,而调试问题有用吗?

    I'm sure there is more missing from this list - after all this varies on what yr doing in the app. You should be asking yourself at every step of the way - what could go wrong in my application? What things would I or the poor chap that will work on this after me find useful whilst debugging a problem?

    这篇关于ASP.NET的Web API日志记录和跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    1403页,肝出来的..

  • 09-07 02:06