开发者

Simple crash report?

I am looking into implementing a simple crash report on my application that will ask the user if he wants or not to send the crash log to us.

I never did a crash report before, what I am used to do is a try/catch around saving the errors to a log file.

  1. What is the correct way to implement a crash report system ?

  2. How do you trigger the crash report to open and send the dump when the application crashs or what开发者_StackOverflow社区 is the correct approch to send the data ?

I think the above are my biggest doubts as to how it works or should work... I am not entirely sure if the crash report would be a interact of try/catchs with a external app trigged when the above happens or what would be the correct way to follow it.

I dont have SQL Server available so what I was planning to use would be a simple upload script that the app to report the dump would use to send the data.

Pardon me for my ignorance about how the crash report works and I hope the community can help me understand it better.

I was searching around about crash report and saw most things going around Crystal Report, ready to go libraries, etc but I would like to start it small so I can get a better understanding of it before digging into some big library or other solution if it is available at my end.


Have you considered using the built-in Windows Error Reporting?

You can use the Winqual website to view driver-specific, application-specific, or operating system-specific errors associated with your organization. Each error report provides details related to that bucket, and you can then request a file of the associated data.

To view error reports:

  1. Establish a Winqual account. To protect companies from impersonation and to ensure that the error reports go to a representative from the correct company, the Winqual Web site requires your company to have a valid VeriSign ID.

• Check with your Legal Department; your company might already have a VeriSign ID (also called a Software Publisher's Digital ID for Authenticode). • Check on Winqual to see if your company already has an account.

  1. Accept the Windows Error Reporting Agreement.

  2. Sign in to the Winqual site.

  3. Click Windows Error Reports.

This old article may be of interest: A Simple Class to Catch Unhandled Exceptions in WinForms


Much depends on the application and (in particular) the anticipated privacy concerns of your users.

Assuming this is a client application running on users' PCs, if this is an "intranet" internal application then it should be quite simple to have the application email the log file to you as the application exits.

This can be quite fun, as sometimes you'll fix the bug before users get around to reporting it.

Alternatively, if you're concerned that the application may crash and the unhandled exception won't be caught properly, you could

  1. On startup, write a registry entry (or dummy file entry, or what-have-you) that marks "application not terminated properly"
  2. On a clean exit, clean up the registry entry (or what-have-you)
  3. On startup, check to see if the registry entry (etc.) exists.

If the marker is present, then you know the application crashed in an un-clean fashion, so you can prompt the user with text e.g. "Last time you ran this program it didn't appear to exit properly. Would you like to send a log of what happened to us so we can try and fix any problem that might have occurred?"


Roll your own exception handler. Use below code in your program.cs class. It will automatically Send mail when exception occurs.

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);
            }
        }
    }
}

You can save your time by getting crash report library based on this one from https://crashreporterdotnet.codeplex.com


Try to use AppDomain.UnHandledException and/or AppDomain.ThreadException

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜