[英]What is the best way to collect/report unexpected errors in .NET Window Applications?
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. 我们的大量产品是安装在远程站点的WinForm和WPF应用程序。 Inevitably unexpected errors occur, from NullReferenceExceptions to 'General network errors'. 从NullReferenceExceptions到“常规网络错误”,不可避免地会发生意外错误。 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 . 目前,使用log4net记录所有这些未处理的异常,然后通过电子邮件发回给我们进行分析 。 However we found that sometimes these error 'reports' contain too little information to identify the problem. 但是我们发现,有时这些错误“报告”包含的信息太少,无法识别问题。
In these reports we need information such as: 在这些报告中,我们需要以下信息:
I don't really want to re-invent the wheel by developing this from scratch. 我真的不想通过从头开始开发这个轮子来重新发明轮子。 Components that are required: 所需的组件:
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. 注意:我们将SmartAssembly视为一种可能的解决方案,但尽管接近它并不能完全满足我们的需求,但我希望能够听到其他开发人员的工作以及是否存在其他替代方案。
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. 也许我在原始问题中并不清楚,问题不在于如何捕获所有无法处理的异常,而是如何处理它们以及围绕它们创建报告引擎(分析)。
我建议杰夫阿特伍德关于用户友好异常处理的文章,它完成了你所要求的大部分内容(应用程序信息,屏幕截图,异常详细信息,操作系统,记录到文本文件和电子邮件),并包含源代码,以便您添加额外的你需要的东西。
You can attach to the unhandled exception event and log it/hit a webservice/etc. 您可以附加到未处理的异常事件并记录/点击webservice / etc。
[STAThread]
static void Main()
{
Application.ThreadException += new ThreadExceptionEventHandler(OnUnhandledException);
Application.Run(new FormStartUp());
}
static void OnUnhandledException(object sender, ThreadExceptionEventArgs t)
{
// Log
}
I also found this code snippet using AppDomain instead of ThreadException: 我还发现这个代码片段使用AppDomain而不是ThreadException:
static class EntryPoint {
[MTAThread]
static void Main() {
// Add Global Exception Handler
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(OnUnhandledException);
Application.Run(new Form1());
}
// In CF case only, ALL unhandled exceptions come here
private static void OnUnhandledException(Object sender,
UnhandledExceptionEventArgs e) {
Exception ex = e.ExceptionObject as Exception;
if (ex != null) {
// Can't imagine e.IsTerminating ever being false
// or e.ExceptionObject not being an Exception
SomeClass.SomeStaticHandlingMethod(ex, e.IsTerminating);
}
}
}
Here is some documentation on it: AppDomain Unhandled Exception 以下是一些文档: 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. 除了自己处理它之外,实际上没有一种通用的方法可以重用,它确实需要与应用程序的接口正确集成,但是你可以设置一个带有应用程序名称,异常和所有这些好东西,并为您的所有应用程序提供集中点。
You may want to study the error reporting feature built into JetBrain's Omea Reader . 您可能想要研究JetBrain的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. 在将问题提交给JetBrain的公共错误收集Web服务之前,用户可以输入更多详细信息。
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 他们使Omea开源,允许社区将.NET 1.1代码库升级到v2或3. http://www.jetbrains.net/confluence/display/OMEA/this+link
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.