You can setup CrashReporter.NET by following below guide. It’s a three step process and you are ready to go.

Step - 1

Add reference of CrashReporter.NET in your project.

2013-07-14_11h46_11

Step - 2

Now following dialog appears click on browse tab and and browse for downloaded CrashReporter.NET.dll file and click OK.

2013-07-14_11h50_36

Step - 3

Now add following lines in your application’s Program.cs file if you want to report all unhandled exceptions.

using System;
using System.Threading;
using System.Windows.Forms;
using CrashReporterDotNET;

namespace Right_Click_Shortcuts_Creator
{
    internal static class Program
    {
        /// <summary>
        ///     The main entry point for the application.
        /// </summary>
        [STAThread]
        private static void Main()
        {

            Application.ThreadException += ApplicationThreadException;

            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());
        }

        private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
        {
            ReportCrash((Exception)unhandledExceptionEventArgs.ExceptionObject);
            Environment.Exit(0);
        }

        private static void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
        {
            ReportCrash(e.Exception);
        }

        private static void ReportCrash(Exception exception)
        {
            var reportCrash = new ReportCrash
            {
                FromEmail = "Your Gmail address",
                ToEmail = "Email address where you want to receive crash reports",
                SmtpHost = "Your SMTP server address for example smtp.gmail.com",
                Port = 587,
                UserName = "Your Gmail address ",
                Password = "Your Gmail password",
                EnableSSL = true,
            };

            reportCrash.Send(exception);
        }
    }
}

If you want to handle exception reporting for individual exception use following code.

using System;
using System.Windows.Forms;
using System.IO;
using CrashReporterDotNET;

namespace CrashReporterTest
{
    public partial class FormMain : Form
    {
        private static void ReportCrash(Exception exception)
        {
            var reportCrash = new ReportCrash
            {
                FromEmail = "Your Gmail address",
                ToEmail = "Email address where you want to receive crash reports",
                SmtpHost = "Your SMTP server address for example smtp.gmail.com",
                Port = 587,
                UserName = "Your Gmail address ",
                Password = "Your Gmail password",
                EnableSSL = true,
            };

            reportCrash.Send(exception);
        }

        public FormMain()
        {
           InitializeComponent();
        }

        private void ButtonTestClick(object sender, EventArgs e)
        {
           try
           {
              File.Copy("Test.txt", "Error.txt");
           }
           catch (Exception exception)
           {
              ReportCrash(exception);
           }
        }
    }
} 

Make sure you use tools like Eazfusctor.NET or any other obfuscation software for .NET framework to protect your email and password from being seen. Also create new gmail account with random password that doesn’t contain secondary email or mobile to use Gmail as a smtp server. This class library is under development and will get many more features in near future. You can use your own SMTP server to send crash reports.

Last edited Jul 14, 2013 at 6:46 AM by ravi15, version 9

Comments

No comments yet.