ravibpatel / CrashReporter.NET

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.
MIT License
184 stars 74 forks source link

VB.NET Example #38

Open igrebel opened 3 years ago

igrebel commented 3 years ago

Hello,

can you show me a little VB.net example? I was trying to include your crashreporter, but have some errors.

Thanks!

EddieDemon commented 3 years ago

Are you using the binaries from NuGet or the raw code? What is the error you're receiving?

PeterStrick commented 3 years ago

Hello,

can you show me a little VB.net example? I was trying to include your crashreporter, but have some errors.

Thanks!

I seem to have gotten CrashReporter.Net to work on VB.Net, see Code Example:

Hope it helps!

Imports System.Threading, CrashReporterDotNET
Public Class Form1
    ''' <summary>
    ''' Main entry point of the Program.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Listen to Application Crashes and show CrashReporter.Net if one occurrs.
        AddHandler Application.ThreadException, AddressOf ApplicationThreadException
        AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomainOnUnhandledException
    End Sub

    ''' <summary>
    ''' Show CrashReporter.Net for unhandled exceptions.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="unhandledExceptionEventArgs"></param>
    Private Shared Sub CurrentDomainOnUnhandledException(sender As Object, unhandledExceptionEventArgs As UnhandledExceptionEventArgs)
        SendReport(DirectCast(unhandledExceptionEventArgs.ExceptionObject, Exception))
        Environment.[Exit](0)
    End Sub

    ''' <summary>
    ''' Show CrashReporter.Net for Application Thread Exceptions.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Shared Sub ApplicationThreadException(sender As Object, e As ThreadExceptionEventArgs)
        SendReport(e.Exception)
    End Sub

    ''' <summary>
    ''' Main Sub that calls CrashReporter.Net to send an error report
    ''' Replace mail@example.com with your or another Email Address.
    ''' You can hide or show the screenshot Tab by setting ShowScreenshotTab to either True or False.
    ''' If you have a https://drdump.com account, you can set your Application GUID according to your Dr.Dump Application, if not remove the .DrDumpSettings section.
    ''' </summary>
    ''' <param name="exception"></param>
    Public Shared Sub SendReport(exception As Exception)
        Dim reportCrash = New ReportCrash("mail@example.com") With {
        .ShowScreenshotTab = True,
        .DoctorDumpSettings = New DoctorDumpSettings With {
            .ApplicationID = New Guid("00000000-0000-0000-0000-000000000000")
            }
        }
        reportCrash.Send(exception)
    End Sub

    ''' <summary>
    ''' Your average Button or Code that is crashing. In this case it is a Button throwing an exception.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Throw New ApplicationException("This is an error, as well as a Test for CrashReporter.Net")
    End Sub
End Class

image