.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:
- Multiple integrations with additional features such as SQL Client, Serilog, log4net, ASP.NET Core, EntityFramework, EntityFramework Core, Xamarin
- Breadcrumbs automatically captured
- Release health tracks crash free users and sessions
- Attachments enrich your event by storing additional files, such as config or log files
- User Feedback provides the ability to collect user information when an event occurs
- Performance Monitoring creates transactions to track the performance of your application
- Automatically captures errors including: unhandled exceptions and unobserved task exceptions
- Events enriched with device data
- Offline caching of events when a device is unable to connect
- Stack Trace Linking to jump directly from a stack trace to the corresponding file in your source code provider; supports Source Link
- Samples provided for multiple C# app models, F# Console, and Giraffe
On this page, we get you up and running with Sentry's SDK.
Using a framework?
Get started using a guide listed in the right sidebar.
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:
dotnet add package Sentry -v 4.3.0
Configuration should happen as early as possible in your application's lifecycle.
For example, initialize with SentrySdk.Init
in your Program.cs
file:
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;
});
After you have configured Sentry in your code, you can also configure the MSBuild setup for your project. While this step is optional, it can greatly improve your Sentry experience.
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
using Sentry;
try
{
throw null;
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
Learn more about manually capturing an error or message in our Usage documentation.
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.
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").
- Package:
- nuget:Sentry
- Version:
- 4.3.0
- Repository:
- https://github.com/getsentry/sentry-dotnet