Add BugSnag to other .NET applications to automatically capture and report exceptions in production.
New to BugSnag? Create an account
Looking for performance monitoring? See our performance guide
Bugsnag
package from NuGet.Bugsnag.dll
in your project.The latest available version of Bugsnag
is v3.1.0
.
For more information, see the Compatibility guide.
Create a BugSnag client when your application starts.
var bugsnag = new Bugsnag.Client(new Configuration("your-api-key-goes-here"));
You can find your API key in Project Settings from your BugSnag dashboard.
After completing installation and basic configuration, unhandled exceptions will be automatically reported to your BugSnag dashboard.
If you would like to send non-fatal exception to BugSnag, you can pass any object that inherits from System.Exception
to the Notify
method
try
{
throw new System.NotImplementedException();
}
catch (System.Exception ex)
{
bugsnag.Notify(ex);
}
You can set the severity of an error in BugSnag by including the severity option when notifying BugSnag of the error
try
{
throw new System.NotImplementedException();
}
catch (System.Exception ex)
{
bugsnag.Notify(ex, Bugsnag.Severity.Info);
}
In order to understand what happened in your application before each error, it can be helpful to leave short log statements that we call breadcrumbs. The last 25 breadcrumbs are attached to an error report to help diagnose what events lead to the error. Captured breadcrumbs are shown on your BugSnag dashboard as a part of the error report.
You can leave manual breadcrumbs via the Breadcrumbs property on the client object.
bugsnag.Breadcrumbs
.Leave("Something happened!");
You can optionally attach a type and metadata to a breadcrumb for additional context into the state of the application when the breadcrumb was captured.
bugsnag.Breadcrumbs
.Leave("Something happened!", Bugsnag.BreadcrumbType.Navigation, null);
With additional diagnostic metadata:
var metadata = new Dictionary<string, string> { { "foo", "bar" } }
bugsnag.Breadcrumbs
.Leave("Something happened!", Bugsnag.BreadcrumbType.State, metadata);
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.
You can manually create a new session when appropriate for your application:
bugsnag.SessionTracking.CreateSession();
Stacktraces from .NET platforms will be automatically populated with line numbers and file names for dlls that the runtime can find symbols for. This usually means that you should deploy the .pdb
files alongside your dlls so that BugSnag is able to retrieve this information.
bugsnag-dotnet
source code