在 .NET Window 应用程序中收集/报告意外错误的最佳方法是什么?
我正在寻找比我们目前处理意外生产错误更好的解决方案,而无需重新发明轮子。
我们的大量产品是安装在远程站点的 WinForm 和 WPF 应用程序。 不可避免地会发生意外错误,从 NullReferenceExceptions 到“一般网络错误”。 因此,范围从程序员错误到环境问题。
目前,所有这些未处理的异常均使用 log4net 进行记录,然后通过电子邮件发回给我们进行分析。 然而,我们发现有时这些错误“报告”包含的信息太少,无法识别问题。
在这些报告中,我们需要以下信息:
- 应用程序名称
- 应用程序版本
- 工作站
- 也许是屏幕截图
- 异常详细信息
- 操作系统
- 可用 RAM
- 运行进程
- 等等...
我真的不想通过从头开始开发来重新发明轮子。 所需组件:
- 错误收集(详细信息如上所述)
- 错误“发送者”(如果数据库或互联网不可用则需要排队)
- 错误数据库
- 对这些错误进行分析和报告。 例如,10 个最常见的错误或超时发生在下午 4:00 到 5:00 之间。 版本 x 和 y 之间的错误如何比较?
笔记: 我们将 SmartAssembly 视为一种可能的解决方案,但尽管很接近,但它并不能完全满足我们的需求,我希望听听其他开发人员做了什么以及是否存在一些替代方案。
编辑:感谢您迄今为止的回答。 也许我最初的问题并不清楚,问题不在于如何捕获所有未处理的异常,而在于如何处理它们并围绕它们创建报告引擎(分析)。
I am looking for a better solution than what we currently have to deal with unexpected production errors, without reinventing the wheel.
A larger number of our products are WinForm and WPF applications that are installed at remote sites. Inevitably unexpected errors occur, from NullReferenceExceptions to 'General network errors'. Thus ranging from programmer errors to environment problems.
Currently all these unhandled exceptions are logged using log4net and then emailed back to us for analysis. However we found that sometimes these error 'reports' contain too little information to identify the problem.
In these reports we need information such as:
- Application name
- Application Version
- Workstation
- Maybe a screen shot
- Exception details
- Operating system
- Available RAM
- Running processes
- And so on...
I don't really want to re-invent the wheel by developing this from scratch. Components that are required:
- Error collection (details as mentioned above)
- Error 'sender' (Queuing required if DB or Internet is unavailable)
- Error database
- Analysis and reporting of these errors. E.g. 10 most frequent errors or timeouts occur between 4:00PM and 5:00PM. How do the errors compare between version x and y?
Note:
We looked at SmartAssembly as a possible solution but although close it didn't quite met our needs and I was hoping to hear what other developers do and if some alternatives exist.
Edit: Thanks for the answers so far. Maybe I wasn't clear in my original question, the problem is not how to catch all unhanded exceptions but rather how to deal with them and to create a reporting engine (analysis) around them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想研究 JetBrain 的 Omea Reader 中内置的错误报告功能。 它有一个包罗万象的错误处理组件,当发生意外错误时会弹出一个对话框。 用户可以在将问题提交到 JetBrain 的公共错误收集 Web 服务之前输入更多详细信息。
他们将 Omea 开源,以允许社区将 .NET 1.1 代码库升级到 v2 或 3。
http://www.jetbrains.net/confluence/display/OMEA/this+链接
You may want to study the error reporting feature built into JetBrain's Omea Reader. It has a catch-all error-handling component that pops a dialog when an unexpected error occurs. The user can input more details before submitting the problem to JetBrain's public error-collection web service.
They made Omea open source to allow the community to upgrade the .NET 1.1 code base to v2 or 3.
http://www.jetbrains.net/confluence/display/OMEA/this+link
您可以附加到未处理的异常事件并记录它/点击网络服务/等等。
我还发现了使用 AppDomain 而不是 ThreadException 的代码片段:
以下是有关它的一些文档: AppDomain 未处理的异常
除了自己处理之外,没有真正可重用的通用方法来执行此操作,它确实需要与应用程序的界面正确集成,但是您可以设置一个 Web 服务,该服务获取应用程序名称、异常以及所有这些好东西,并为所有应用程序提供一个集中点。
You can attach to the unhandled exception event and log it/hit a webservice/etc.
I also found this code snippet using AppDomain instead of ThreadException:
Here is some documentation on it: AppDomain Unhandled Exception
Outside of just handling it yourself, there isn't really a generic way to do this that is reusable, it really needs to be integrated with the interface of the application properly, but you could setup a webservice that takes application name, exception, and all that good stuff and have a centralized point for all your apps.
我建议 Jeff Atwood 的关于 用户友好的异常处理 的文章,该文章大部分内容您已经询问过的内容(应用程序信息、屏幕截图、异常详细信息、操作系统、记录到文本文件和电子邮件),并包含源代码,以便您添加所需的额外内容。
I'd suggest Jeff Atwood's article on User Friendly Exception Handling, which does most of what you ask already (Application Info, Screenshot, Exception Details, OS, Logging to text files and Emailing), and contains the source code so you add the extra stuff you need.