.NET

Learn how to set up and run Sentry's .NET SDK, which will automatically report errors and exceptions in your application.

If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.

This SDK is compatible with the latest .NET and .NET Core platforms, as well as .NET Standard 2.0 and .NET Framework 4.6.2 or newer. You can use it with applications written in C#, VB.NET, F#, and other .NET programming languages. For older versions, such as .NET Framework 3.5, you may continue to use our legacy SDK, until further notice. Check out related guides in the dropdown menu on the left.

In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling.

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

Sentry captures data by using an SDK within your application’s runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.

Install the NuGet package to add the Sentry dependency:

Sentry profiling for .NET is available in Alpha on .NET 6.0+ (tested on .NET 7.0 & .NET 8.0 as well).

Copied
dotnet add package Sentry.Profiling -v 4.10.2

To capture all errors, even the one during the startup of your application, you should initialize the Sentry .NET SDK as soon as possible.

Copied
SentrySdk.Init(options =>
{
    options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.us.sentry.io/5428537";
    options.Debug = true;
    options.AutoSessionTracking = true;
    // A fixed sample rate of 1.0 - 100% of all transactions are getting sent
    options.TracesSampleRate = 1.0f;
    // A sample rate for profiling - this is relative to TracesSampleRate
    options.ProfilesSampleRate = 1.0f;
});

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);
}
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").