什么日志记录对您的应用程序来说是好的日志记录? [英] What logging is good logging for your app?

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

问题描述

因此,我们在我的工作场所讨论过登录日志,我想知道这里的一些人是否可以给我一些有关您的方法的想法?

So we've discussed logging in passing at my place of work and I was wondering if some of you guys here could give me some ideas of your approaches?

通常情况下,实际上根本没有日志记录,主要是.NET应用程序,winforms/WPF客户端通过Web服务进行通信或直接进入db.

Typically our scenario is, no logging really at all, and mostly .NET apps, winforms/WPF clients talking through web services or direct to a db.

所以,真正的问题是,您将在哪里记录什么?目前,我们有用户报告错误消息-因此,我假设日志启动/关闭,异常...

So, the real question is, where or what would you log? At the moment we have users reporting error messages - so I would assume log startups/shutdowns, exceptions...

您是否将其用于调用Web服务或数据库?页面加载了吗?

Do you take it to calls to the web services or db? Page loads?

您如何很好地了解用户当时想做什么?

How do you get a good idea of what the user was trying to do at the time?

一路走好,并记录多次尝试/每一天的所有记录,还是只记录所需的记录(考虑到HDD便宜)是更好的选择.

Is it better to go all the way and log everything across multiple attempts/days, or log only what you need to (given hdd is cheap).

我想这是几个问题,但我想更多地了解大型商店的实际做法!

I guess that's a few questions, but I wanted to get more of an idea of what the actual practice is out there in larger shops!

推荐答案

记录的关键是好的计划.我建议您调查企业库异常和日志记录应用程序块( http: //msdn.microsoft.com/zh-CN/library/cc467894.aspx ).学习曲线有些微不足道,但效果确实很好.我目前支持的方法是定义4个优先级. 4 =未处理的异常(事件日志中的错误),3 =处理的异常(事件日志中的警告),2 =访问外部资源,例如Web服务,数据库或大型机系统(事件日志中的信息),1 =详细信息/其他感兴趣(事件日志中的信息).

The key thing for logging is good planning. I would suggest that you look into the enterprise library exception and logging application block (http://msdn.microsoft.com/en-us/library/cc467894.aspx). There is a wee bit of a learning curve but it does work quite well. The approach I favour at the moment is to define 4 priority levels. 4=Unhandled exception (error in event log), 3=Handled exception (warning in event log), 2=Access an external resource such as a webservice, db or mainframe system (information in event log), 1=Verbose/anything else of interest (information in event log).

使用应用程序块,可以很容易地调整您要记录的优先级.因此,在开发过程中,您会记录所有内容,但是当您在生产环境中获得稳定的系统时,您可能只会对未处理的异常以及可能的已处理异常感兴趣.

Using the application block it's then quite easy to tweak what level of priority you want to log. So in development you'd log everything but as you get a stable system in production, you'd probably only be interested in unhandled exceptions and possibly handled exceptions.

更新:为清楚起见,我建议您同时登录winform/wpf应用程序和Web服务.在Web场景中,过去我遇到了一些问题,在该问题上,很难将客户端的错误重新绑定到应用程序服务器.主要是因为通过Web服务进行的任何错误都被包装为SOAP异常.我想不起来,但是我想如果您使用自定义异常处理程序(这是企业库的一部分),则可以将数据添加到异常中,例如来自应用服务器的异常的handlinginstance id.通过使用LogParser(

Update: For clarity, I would suggest you have logging in both your winform/wpf app and your webservices. In a web scenario, I've had problems in the past where it can be difficult to tie an error on the client back through to the app servers. Mainly because any error through webservices gets wrapped up as a SOAP exception. I can't remember off the top of my head, but I think if you use a custom exception handler (that is part of the enterprise library) you can add data onto exceptions such as the handlinginstance id of the exception from the app server. This makes it easier to tie up exceptions on a client back to your app box by using LogParser (http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en).

第二次更新:我也想给每个不同的事件一个单独的事件ID,并在源代码控制下在文本文件或电子表格中对其进行跟踪.是的,这很痛苦,但是如果您有幸让IT团队照顾您的生产系统,我会发现他们倾向于期望不同的事件具有不同的事件ID.

Second Update: I also like to give each different event a seperate event id and to track that in a text file or spreadsheet under source control. Yes, its a pain but if you're lucky enough to have an IT team looking after your systems in production, I find they tend to expect different events to have different event ids.

这篇关于什么日志记录对您的应用程序来说是好的日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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