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

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

问题描述

因此,可以说我正好在我的应用程序中未处理的异常或崩溃的某些原因。
是否有某种方式为我捕获输出并显示错误报告对话框时,应用程序崩溃。

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.

报告该错误消息将是一件容易的事,但我不知道如何捕捉未处理的异常的输出或抢退出代码(我假设,当它导致程序崩溃会给其他然后退出代码0)。

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:

  • AppDomain.UnhandledException is the ultimate 'catch-all'
  • Application.ThreadException is the UI specific catch-all for exceptions that occurred in Forms threads

适当的位置为'包罗万象'取决于应用程序的语义,很难说你应该把它的w / o知道你的应用程序。应用程序还需要设置 Application.SetUnhandledExceptionMode

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.

具有外部看门狗不太有用,因为它不能给为啥应用程序的任何有意义的信息崩溃。到时候它检测到意外退出(它是如何知道是'意外'?)是太晚收集任何有用的信息。随着内部处理程序,你可以收集异常和堆栈,并提交到分析服务,如 bugcollect.com ,然后你将有一个腿领先理解现在只有的什么的发生,但也的频率的它发生和部署都受到影响(其中的它发生) 。还有像 exceptioneer.com 或的 Windows错误报告(这个需要你的代码由如Verisign信任的机构证书签名)。依托于对事件的收集服务远远优于发送邮件,你不想醒来,发现收件箱中的2K事件的电子邮件,并开始通过他们筛选理解的什么的发生。

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.

和最后的世界:不要重新发明轮子:目前已经有很多的框架,收集和记录异常,像的 log4net的 ELMAH

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天全站免登陆