您有没有建议用于.NET的错误报告框架?我需要像通过电子邮件附加文件的电子邮件报告等选项。用户应该能够向报告添加信息,并且还应该能够删除报告文件,即如果它们包含隐私关键数据。还应该有自动截图的可能性。
所需的框架还应包括错误报告GUI。它应该给我创建自己的GUI进行错误报告的可能性。
我已经使用了log4net,但据我所知,它不可能向用户显示错误报告GUI。
如果有任何建议,那就太好了。
问候,马丁
您有没有建议用于.NET的错误报告框架?我需要像通过电子邮件附加文件的电子邮件报告等选项。用户应该能够向报告添加信息,并且还应该能够删除报告文件,即如果它们包含隐私关键数据。还应该有自动截图的可能性。
所需的框架还应包括错误报告GUI。它应该给我创建自己的GUI进行错误报告的可能性。
我已经使用了log4net,但据我所知,它不可能向用户显示错误报告GUI。
如果有任何建议,那就太好了。
问候,马丁
自定义异常处理程序。在您的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);
}
}
}
}
我熟悉“Microsoft Enterprise Library Logging Block”和“Log4Net”,这两个都符合您的要求(具有多个日志侦听器)。 这里有一个比较这两个工具的网页:http://weblogs.asp.net/lorenh/archive/2005/02/18/376191.aspx
Red Gate有一个名为SmartAssembly的产品,可进行错误报告。我自己没有使用过它,但该公司信誉良好。