.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, until further notice.

Features:

On this page, we get you up and running with Sentry's SDK.

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

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 4.4.0

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

For example, initialize with SentrySdk.Init in your Program.cs file:

Copied
using Sentry;

SentrySdk.Init(options =>
{
    // A Sentry Data Source Name (DSN) is required.
    // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
    // You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
    options.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/0";

    // When debug is enabled, the Sentry client will emit detailed debugging information to the console.
    // This might be helpful, or might interfere with the normal operation of your application.
    // We enable it here for demonstration purposes when first trying Sentry.
    // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
    options.Debug = true;

    // This option is recommended. It enables Sentry's "Release Health" feature.
    options.AutoSessionTracking = true;

    // Enabling this option is recommended for client applications only. It ensures all threads use the same global scope.
    options.IsGlobalModeEnabled = false;

    // This option will enable Sentry's tracing features. You still need to start transactions and spans.
    options.EnableTracing = true;

    // Example sample rate for your transactions: captures 10% of transactions
    options.TracesSampleRate = 0.1;
});

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!) or suggesting an update ("yeah, this would be better").