.NET的错误报告框架

10

您有没有建议用于.NET的错误报告框架?我需要像通过电子邮件附加文件的电子邮件报告等选项。用户应该能够向报告添加信息,并且还应该能够删除报告文件,即如果它们包含隐私关键数据。还应该有自动截图的可能性。

所需的框架还应包括错误报告GUI。它应该给我创建自己的GUI进行错误报告的可能性。

我已经使用了log4net,但据我所知,它不可能向用户显示错误报告GUI。

如果有任何建议,那就太好了。

问候,马丁


1
另请参见http://stackoverflow.com/questions/49224/good-crash-reporting-library-in-c - dan-gph
Visual Studio Application Insights是您所需要的!https://azure.microsoft.com/zh-cn/documentation/articles/app-insights-windows-desktop/ - smedasn
9个回答

5

你尝试过 Elmah 吗?它可以处理你所说的所有错误处理元素。你可能会对 Trac 感兴趣,它可以满足你想要的 bug 追踪部分。

祝好,

Dan


4

自定义异常处理程序。在您的program.cs类中使用以下代码。当异常发生时,它将自动发送邮件。

using System;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Threading; 

namespace ExceptionHandlerTest
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.ThreadException +=
                new ThreadExceptionEventHandler(Application_ThreadException);

            // Your designer generated commands.
        }

        static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) 
        {

            var fromAddress = new MailAddress("your Gmail address", "Your name");
            var toAddress = new MailAddress("email address where you want to receive reports", "Your name");
            const string fromPassword = "your password";
            const string subject = "exception report";
            Exception exception = e.Exception;
            string body = exception.Message + "\n" + exception.Data + "\n" + exception.StackTrace + "\n" + exception.Source;

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body
            })
            {
                //You can also use SendAsync method instead of Send so your application begin invoking instead of waiting for send mail to complete. SendAsync(MailMessage, Object) :- Sends the specified e-mail message to an SMTP server for delivery. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes. 
                smtp.Send(message);
            }
        }
    }
}

太好了,谢谢!我希望我能将您的答案标记为正确。我在我的项目中使用了它,而且完美地运行。我发现如果捕获异常,则不会调用邮件报告。但是我已经从中制作了一个类,并在“try,catch”中调用它,因此用户仍然可以在视觉上获得错误报告。 - MiKE
我喜欢简单易懂的程序,但我不喜欢在程序中硬编码密码,这样容易被滥用。应该有一种方法来封装它,使其不能轻易地从 MSIL 程序集中查看。 - rollsch
1
@rolls 我把这段代码封装成了一个库,现在不需要SMTP的电子邮件了。它使用Drdump服务来收集崩溃信息。你可以在 https://crashreporterdotnet.codeplex.com/ 找到它。 - Ravi Patel

4

我已经在使用log4net,但是log4net是否有创建崩溃报告窗口的可能性?由于隐私原因,无法使用日志文件生成自动化邮件。用户必须可以决定是否报告崩溃。 - martin

3

3

Red Gate有一个名为SmartAssembly的产品,可进行错误报告。我自己没有使用过它,但该公司信誉良好。


请注意,您不能在Visual Studio在线构建管道中使用它,因为它需要安装许可证密钥。如果您能够解决此问题,请向我发送解决方案 :) - Ognyan Dimitrov

1

请查看企业库,您可以获得一个完全可配置和可扩展的日志记录和异常处理应用程序日志。


1

Microsoft WER,但是你需要在Winqual上注册并且你的公司需要有VeriSign ID。对很多人来说太麻烦了。


0

你也可以尝试使用log4net。虽然我不确定是否支持电子邮件,但它是可扩展的。此外,你还可以获取源代码!


0

微软的企业库,最新版本4.1-2008年10月广泛用于异常处理和日志记录等方面。此外还有一个不错的GUI构建器,可以修改您的app.config或web.config文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接