来自WPF应用程序的异常报告 [英] Exception reporting from a WPF Application

查看:165
本文介绍了来自WPF应用程序的异常报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以让我们说我碰巧在我的应用程序中有一个未处理的异常,或者因为某些原因而崩溃。
有一些方法可以捕获输出并在应用程序崩溃时显示错误报告对话框。



我在想的是在后台运行一个小程序,只有工作是监听主应用程序的异常退出,然后显示报告'对话框,用户可以选择向我发送错误的输出。



不太确定如何实现这个,或者这是正确的方法。



报告错误消息将是一个容易的任务,但我不知道如何捕获未处理的异常的输出或抓取退出代码(我假设该程序会给出一个退出代码,否则为0,当它崩溃)。



在正确的方向进行微调是非常好的。

解决方案

你最好的机会在应用程序内。有两个钩子:





适当的抓住所有的地方取决于你的应用程序语义,很难说你应该在哪里知道你的应用程序。应用程序还需要设置 Application.SetUnhandledExceptionMode



拥有外部看门狗不太有用,因为它不能给出任何有意义的信息,为什么应用程序崩溃当它检测到一个意外的出口(它是如何知道是意外的?)太迟收集任何有用的信息。使用内部处理程序,您可以收集异常和堆栈,并将其提交给分析服务,如 bugcollect.com ,然后您将有一条腿在理解现在只有发生了什么,而且它发生的频率以及哪些部署受到影响(其中发生)。还有其他类似的服务,如 exceptioneer.com Windows错误报告(这个要求您的代码由受信任的权威证书(如Verisign)签名)。依靠收集事件的服务远远优于发送邮件,您不想在收件箱中醒来并发现2k个事件电子邮件,并开始筛选他们以了解发生了什么。 p>

最后一个世界:不要重新发明:已经有很多框架来收集和记录异常,如 log4net elmah


So lets say I happen to have an unhandled exception in my application or it crashes for some reason. Is there some way for me to capture the output and show an error report dialog when the application crashes.

What I'm thinking is having a small program running in the background, which only job is to listen for an abnormal exit of the main application and then show the 'report' dialog where the user could choose to email me the output of the error.

Not really sure how to implement this, or if this is the right way to do it.

Reporting the error message would be an easy task, but I have no idea how to capture the output of an unhandled exception or grab the exit codes (I'm assuming the program would give an exit code other then 0 when it crashes).

Would be great to have a nudge in the right direction.

解决方案

Your best chance is inside the application. There are two hooks:

The proper place to 'catch-all' depends on your application semantics and is difficult to say where you should put it w/o knowing your application. Application need to also set the Application.SetUnhandledExceptionMode.

Having an external watch dog is less useful because it cannot give any meaningful information why did the application crash. By the time it detect an 'unexpected' exit (how does it knows is 'unexpected'?) is way too late to collect any useful information. With an inside handler you can collect the exception and the stack and submit them to an analysis service like bugcollect.com and then you'll have a leg ahead in understanding now only what happened, but also how often it happens and which deployment are affected (where it happens). There are other similar services like exceptioneer.com or the Windows Error Reporting (this one requires your code to be signed by a trusted authority certificate like Verisign). Relying on a service for collection of incidents is far superior to sending mail, you don't want to wake up and find 2k incident emails in your inbox and start sifting through them to understand what happened.

And a final world: don't reinvent the wheel: there are already many frameworks to collect and log exceptions, like log4net and elmah.

这篇关于来自WPF应用程序的异常报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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