WPF integration guide

Add BugSnag to your WPF applications to automatically capture and report exceptions in production.

New to BugSnag? Create an account

Looking for performance monitoring? See our performance guide

Installation

  • Install the Bugsnag package version 1.4.0 from NuGet.

Manual installation

  • Download version 1.4.0 of Bugsnag.dll located within the bugsnag.zip file.
  • Reference Bugsnag.dll in your project.

BugSnag for .NET depends only on the JSON.net library and needs to be referenced, the nuget package can be found here.

Basic configuration

  1. Configure the BugSnag integration inside your App.config file

    <configuration>
      <configSections>
        <section name="bugsnagConfig" type="Bugsnag.ConfigurationStorage.ConfigSection, Bugsnag" />
      </configSections>
      <bugsnagConfig apiKey="your-api-key-goes-here" />
    </configuration>
    
  2. Import the BugSnag clients namespace into your application

    using Bugsnag.Clients;
    
  3. Inside the OnStartup function call the WPFClient.Start() method. Normally, this can be done in the App.xaml.cs file.

    WPFClient.Start();
    

Reporting unhandled exceptions

After completing installation and basic configuration, unhandled exceptions will be automatically reported to your BugSnag dashboard.

Reporting handled exceptions

If you would like to send non-fatal exceptions to BugSnag, you can pass any object that inherits from Exception to the Notify method:

WPFClient.Notify(new ArgumentException("Non-fatal"));

Sending diagnostic data

It is often helpful to send us additional application-specific diagnostic data. This can be accomplished as per the following example:

var metadata = new Metadata();
metadata.AddToTab("Resources", "Datastore Entries", myDataStore.Count());
metadata.AddToTab("Resources", "Threads Running", threads.Count());
metadata.AddToTab("Resources", "Throttling Enabled", false);

WPFClient.Notify(new ArgumentException("Non-fatal"), metadata);

Customizing report severity

You can set the severity of an error in BugSnag by including the severity option when notifying bugsnag of the error,

WPFClient.Notify(new ArgumentException("Non-fatal"), Severity.Info)

Valid severities are Severity.Error, Severity.Warning and Severity.Info.

Severity is displayed in the dashboard and can be used to filter the error list.

By default all crashes (or unhandled exceptions) are set to Severity.Error and all WPFClient.Notify() calls default to Severity.Warning.

Identifying users

The client can be configured to send the users ID, email and name with every notification. The user ID should be set to something unique to the user e.g. a generated GUID.

WPFClient.Config.SetUser("d7b4aadd", "anth.m@mycompany.com", "Anthony Michaels");

Session tracking

BugSnag can track the number of “sessions” that happen in your application. This enables BugSnag to provide and compare stability scores between releases to help you understand the quality of your releases.

Session tracking is coming soon to this platform.

Next steps