.NET

The Sentry .NET SDK supports all recent versions of the .NET platform, and integrates well with a variety of popular frameworks and packages in the ecosystem. You can use it with applications written in C#, VB.NET, F#, and other .NET programming languages. It gives developers helpful hints for where and why an error or performance issue might have occurred.

This SDK is compatible with the latest .NET and .NET Core platforms, as well as .NET Standard 2.0 and .NET Framework 4.6.1 or newer. For older versions, such as .NET Framework 3.5, you may continue to use our legacy SDK.

Features:

On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.

Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.

Install

Sentry captures data by using an SDK within your application’s runtime.

Install the NuGet package to add the Sentry dependency:

Copied
dotnet add package Sentry -v 3.21.0

Configure

Configuration should happen as early as possible in your application's lifecycle.

For example, initialize in the Main method in Program.cs:

Program.cs
Copied
using (SentrySdk.Init(o =>
{
    // Tells which project in Sentry to send events to:
    o.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/0";
    // When configuring for the first time, to see what the SDK is doing:
    o.Debug = true;
    // Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
    // We recommend adjusting this value in production.
    o.TracesSampleRate = 1.0;
    // Enable Global Mode if running in a client app
    o.IsGlobalModeEnabled = true;
}))
{
    // App code goes here - Disposing will flush events out
}

Verify

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:

Copied
using Sentry;

try
{
    throw null;
}
catch (Exception ex)
{
    SentrySdk.CaptureException(ex);
}

To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").