Skip to content

Sample Usage

Peter van der Woude edited this page Aug 10, 2018 · 48 revisions

To include the Exception Reporter within your application either add a Reference to ExceptionReporter.NET.dll to your project (and manually include the dependencies of DotNetZip and SimpleMapi) or use Nuget - see https://www.nuget.org/packages/ExceptionReporter/

Install-Package ExceptionReporter

Example Usage #1 - Direct Show

You might have a high-level point in the code where most exceptions will be thrown. In this case, simply catch the Exception and invoke ExceptionReporter.NET.

You would probably create and setup the config somewhere else to make the code cleaner, but here's an example using SMTP:

 using ExceptionReporting;
 
 try {
    //... some code that can throw
 }
 catch (Exception exception) 
 {
     var reporter = new ExceptionReporter(); 

     reporter.Config.AppName = "PhotoFuzz";
     reporter.Config.CompanyName = "Fuzz Pty Ltd";
     reporter.Config.TitleText = "PhotoFuzz Error Report";
     reporter.Config.EmailReportAddress = "support@fuzz.com";
     reporter.Config.TakeScreenshot = true;   // attached if sending email
     reporter.Config.FilesToAttach = new[]() { "c:/my-app/config.ini", "errors.log" }; 
     reporter.Config.SendMethod = ReportSendMethod.SMTP;  // see also WebService/SimpleMAPI
     reporter.Config.SmtpServer = "127.0.0.1";
     reporter.Config.SmtpPort = 2500;
     reporter.Config.SmtpUsername = "";
     reporter.Config.SmtpPassword = "";
     reporter.Config.SmtpFromAddress = "test@test.com";
     reporter.Config.EmailReportAddress = "support@fuzz.com";
   
     // files to attach are automatically zipped into a single file and 
     // attached, if sending via email 
     
     reporter.Show(exception);    // can also pass multiple exceptions here  
     // reporter.Send(exception)  // sends without showing a dialog (SMTP/WebService)
  }

Example 2 - WinForms unhandled exception

 using ExceptionReporting;
 //...
 
 Application.ThreadException += new ThreadExceptionHandler().ApplicationThreadException;
 //...
 internal class ThreadExceptionHandler
 {   
     public void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
     {
         ExceptionReporter reporter = new ExceptionReporter();
         reporter.Show(e.Exception);
     }
 }

Clone this wiki locally