-
Notifications
You must be signed in to change notification settings - Fork 32
Sample Usage
Peter van der Woude edited this page Sep 2, 2018
·
48 revisions
To include ExceptionReporter.NET within your application either add a Reference to ExceptionReporter.NET.dll to your project (and manually include the dependencies of DotNetZip, SimpleMapi and Handlebars.NET) or use Nuget - see https://www.nuget.org/packages/ExceptionReporter/
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 ExceptionReporting;
try {
//... some code that can throw
}
catch (Exception exception)
{
var er = new ExceptionReporter();
er.Config.AppName = "PhotoFuzz";
er.Config.CompanyName = "Fuzz Pty Ltd";
er.Config.TitleText = "PhotoFuzz Error Report";
er.Config.EmailReportAddress = "support@fuzz.com";
er.Config.TakeScreenshot = true; // attached if sending email
er.Config.FilesToAttach = new[] { "c:/app/config.ini", "c:/app/error.log" };
er.Config.SendMethod = ReportSendMethod.SMTP; // also WebService/SimpleMAPI
er.Config.SmtpServer = "127.0.0.1";
er.Config.SmtpPort = 2500;
er.Config.SmtpUsername = "jon";
er.Config.SmtpPassword = "1234";
er.Config.SmtpFromAddress = "test@test.com";
er.Config.EmailReportAddress = "support@fuzz.com";
// files to attach are automatically zipped into a single file and
// attached, if sending via email (SMTP/SimpleMAPI)
er.Show(exception); // can also pass multiple exceptions here
// er.Send(exception) // sends without showing dialog (SMTP/WebService)
}
Attach an event handler to the Application.ThreadException
event before calling Application.Run()
using ExceptionReporting;
[STAThread]
static void Main()
{
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
//...
Application.Run(new Form1());
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
ExceptionReporter er = new ExceptionReporter();
er.Show(e.Exception);
}
Attach an event handler to the DispatcherUnhandledException
event
public App()
{
DispatcherUnhandledException += OnDispatcherUnhandledException;
}
void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
ExceptionReporter er = new ExceptionReporter();
er.Show(e.Exception);
}