.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.

You can use these instructions to run Sentry in an app running on:

  • Windows
  • macOS
  • Linux
  • Android
  • iOS

If you're using a framework, such as ASP.NET Core or MAUI, please select the framework on the drop down on the top 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 and newer.

Copied
dotnet add package Sentry -v 4.13.0
dotnet add package Sentry.Profiling -v 4.13.0

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