GithubHelp home page GithubHelp logo

ducseb / crashreporter.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ravibpatel/crashreporter.net

0.0 0.0 0.0 174 KB

Send crash reports of your classic desktop application developed using .NET Framework directly to your mail's inbox with full exception report, stack trace and screenshot.

License: MIT License

C# 100.00%

crashreporter.net's Introduction

CrashReporter.NET

AppVeyor branch Donate

Send crash reports of your classic desktop application developed using .NET Framework directly to your mail's inbox with full exception report, stack trace and screenshot.

The nuget package NuGet NuGet

PM> Install-Package CrashReporter.NET.Official

How it works

CrashReporter.NET uses the exception information like stack trace, exception type, message, source, .NET CLR version, OS version and application version to generate the crash report and send it to developer using email. It uses DoctorDump service to send email to developer. Developers can use their SMTP server to send email too.

Using the code

Windows Forms Application

First thing you need to do is subscribe to Application.ThreadException and AppDomain.CurrentDomain.UnhandledException in your Program.cs file as shown below.

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)
    {
        SendReport((Exception)unhandledExceptionEventArgs.ExceptionObject);
    }

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

    public static void SendReport(Exception exception,  string developerMessage = "", bool silent = false)
    {
        var reportCrash = new ReportCrash("Email where you want to receive crash reports")
        {
            DeveloperMessage = developerMessage
        };
        reportCrash.Silent = silent;
        reportCrash.Send(exception);
    }
}

Just set the ToEmail in above example with your email to start receiving crash reports.

If you want to handle exception report for individual exception with special message you can do it like shown below.

const string path = "test.txt";
try
{
    if (!File.Exists(path))
    {
        throw new FileNotFoundException(
            "File Not found when trying to write argument exception to the file", argumentException);
    }
}
catch (Exception exception)
{
    Program.SendReport(exception, "Value of path variable is " + path);
}

WPF Application

First thing you need to do is subscribe to AppDomain.CurrentDomain.UnhandledException in your App.xaml.cs file as shown below.

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
        Application.Current.DispatcherUnhandledException += DispatcherOnUnhandledException;
        TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
    }

    private void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
    {
        SendReport(unobservedTaskExceptionEventArgs.Exception);
    }

    private void DispatcherOnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs dispatcherUnhandledExceptionEventArgs)
    {
        SendReport(dispatcherUnhandledExceptionEventArgs.Exception);
    }

    private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
    {
        SendReport((Exception)unhandledExceptionEventArgs.ExceptionObject);
    }

    public static void SendReport(Exception exception, string developerMessage = "", bool silent = false)
    {
        var reportCrash = new ReportCrash("Email where you want to receive crash reports")
        {
            DeveloperMessage = developerMessage
        };
        reportCrash.Silent = silent;
        reportCrash.Send(exception);
    }
}

Just set the ToEmail in above example with your email to start receiving crash reports.

If you want to handle exception report for individual exception with special message you can do it like shown below.

const string path = "test.txt";
try
{
    if (!File.Exists(path))
    {
        throw new FileNotFoundException(
            "File Not found when trying to write argument exception to the file", argumentException);
    }
}
catch (Exception exception)
{
    App.SendReport(exception, "Value of path variable is " + path);
}

Configuration Options

Send reports Silently

You can send crash reports silently by setting Silent property to true.

reportCrash.Silent = true;

Send reports using a web proxy

You can send crash report using a web proxy by adding following line in SendReport method.

reportCrash.WebProxy = new WebProxy("Web proxy address"),

Send reports to your DrDump account

You can send crash report to you doctor dump account by adding following line in SendReport method.

reportCrash.DoctorDumpSettings = new DoctorDumpSettings
{
    ApplicationID = new Guid("Application ID you received from DrDump.com"),
};

Just set the ApplicationID to ID you received from DrDump.com.

Capture whole screen instead of Application screen

You can take screenshot of whole screen instead of only application when application crashes by adding following line in SendReport method.

reportCrash.CaptureScreen = true;

crashreporter.net's People

Contributors

damirporobic avatar doctordump avatar ducseb avatar jjwalter2001 avatar kochspet avatar milleniumbug avatar ravibpatel avatar shgeum avatar tarekwiz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.