简体   繁体   English

在.NET窗口应用程序中收集/报告意外错误的最佳方法是什么?

[英]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: 在这些报告中,我们需要以下信息:

  1. Application name 应用名称
  2. Application Version 应用版本
  3. Workstation 工作站
  4. Maybe a screen shot 也许是一个屏幕截图
  5. Exception details 例外细节
  6. Operating system 操作系统
  7. Available RAM 可用内存
  8. Running processes 运行流程
  9. And so on... 等等...

I don't really want to re-invent the wheel by developing this from scratch. 我真的不想通过从头开始开发这个轮子来重新发明轮子。 Components that are required: 所需的组件:

  1. Error collection (details as mentioned above) 错误收集(详情如上所述)
  2. Error 'sender' (Queuing required if DB or Internet is unavailable) 错误'发件人'(如果数据库或互联网不可用,则需要排队)
  3. Error database 错误数据库
  4. Analysis and reporting of these errors. 分析和报告这些错误。 Eg 10 most frequent errors or timeouts occur between 4:00PM and 5:00PM. 例如,10个最常见的错误或超时发生在下午4:00到下午5:00之间。 How do the errors compare between version x and y? 版本x和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. 注意:我们将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.

相关问题 收集崩溃数据的最佳方法是什么? - What is the best way to collect crash data? 在.Net中收集大量数据的最简洁方法是什么? - What is the tidiest way to collect lots of data in .Net 在ASP.NET应用程序之间传递对象的最佳方法 - Best way to pass object between asp.net applications output Bitmap 在 window (WPF) 中的最佳方法是什么? - What is the best way to output Bitmap in a window (WPF)? 处理跨多个应用程序的电子邮件分发的最佳方法是什么? - What is the best way to handle email distribution across many applications? 使共享库可用于多个应用程序的最佳方法是什么? - What is the best way to make shared libraries available to multiple applications? .Net Windows服务向用户报告错误的最佳方式 - Best way for a .Net Windows service to report an error to the user 修复“在意外时间调用方法”错误的最佳方法是什么 - What is the best way to fix “A method was called at an unexpected time” error 通过网络传输大型报告的最佳方法是什么? - What is the best way to transfer a large report over the wire? 在.NET中更新MsAccess表的最佳方法是什么 - What is the best way to update a MsAccess table in .NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM