【问题标题】:Error-reporting framework for .net.net 的错误报告框架
【发布时间】:2010-12-26 17:37:18
【问题描述】:

您是否建议在 .net 中使用错误报告框架。我需要像电子邮件报告这样的可能性,文件附加到电子邮件。用户应该可以将信息添加到报告中,也应该可以删除报告文件,即如果它们包含隐私关键数据。还应该有可能进行自动屏幕截图。 所需的框架还应该包括错误报告 gui。它应该让我有可能创建自己的 gui 来报告错误。

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

如果有什么建议就好了,

你好,马丁

【问题讨论】:

标签: c# .net error-handling error-reporting bug-tracking


【解决方案1】:

你试过Elmah吗?它执行您所说的所有错误处理元素。您可以查看 Trac 以获取您想要的错误修复位。

善良,

【讨论】:

    【解决方案2】:

    我熟悉“Microsoft Enterprise Library Logging Block”和“Log4Net”,它们都符合您的要求(具有多个日志侦听器) 这是一个比较这两者的页面:http://weblogs.asp.net/lorenh/archive/2005/02/18/376191.aspx

    【讨论】:

    • 我已经使用 log4net,但是 log4net 有可能创建一个崩溃报告窗口吗?由于隐私原因,无法使用日志文件生成自动邮件。用户必须能够决定是否报告崩溃。
    【解决方案3】:

    滚动您自己的异常处理程序。在您的 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”中调用它,因此用户仍然可以直观地看到错误报告。
    • 我喜欢简单,但我不喜欢程序中的硬编码密码,容易被滥用,应该是一种包装方式,因此不能从 MSIL 程序集中轻松查看。
    • @rolls 我用这段代码创建了现在不需要电子邮件的 SMTP 库。它使用 Drdump 服务来收集崩溃。你可以在crashreporterdotnet.codeplex.com找到它
    【解决方案4】:

    查看The Object Guy制作的日志框架

    【讨论】:

      【解决方案5】:

      Red Gate 有一个名为 SmartAssembly 的产品,它负责错误报告。我自己没用过,但是公司口碑不错。

      【讨论】:

      • 请注意,您不能在 Visual Studio 在线构建管道中使用它,因为它需要使用许可证密钥进行安装。如果可以 - 将解决方案发送给我 :)
      【解决方案6】:

      检查Enterprise Library,您有一个完全可配置和可扩展的日志记录和异常处理应用程序日志。

      【讨论】:

        【解决方案7】:

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

        【讨论】:

          【解决方案8】:

          Microsoft 的Enterprise Library,最新版本4.1-October 2008 广泛用于异常处理和日志记录等。还有一个不错的 GUI 构建器,可以修改您的 app.config 或 web.config 文件。

          【讨论】:

            【解决方案9】:

            你也可以试试log4net。不过,我不确定是否要发送电子邮件。但是,它是可扩展的。另外,您可以获取源代码!

            【讨论】:

              猜你喜欢
              • 2011-03-18
              • 2013-03-03
              • 2011-07-20
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2015-04-19
              • 2015-12-21
              • 1970-01-01
              相关资源
              最近更新 更多