Docs · .NET

SDKs

.NET

Bugzor works with the open-source Sentry NuGet packages. Tested with Sentry 7.0 on .NET 9 (console app).

Console apps and services#

Terminal
dotnet add package Sentry
Program.cs
using Sentry;

using (SentrySdk.Init(options =>
{
    options.Dsn = "https://<public-key>@www.bugzor.com/<project-id>";
    options.Environment = "production";
    options.Release = "my-app@1.0.0";
}))
{
    try
    {
        int.Parse("not a number");
    }
    catch (Exception e)
    {
        SentrySdk.CaptureException(e);
    }

    SentrySdk.CaptureMessage("Hello from .NET");
}

Disposing the object that SentrySdk.Init returns flushes pending events, so keep the using around your whole program. Unhandled exceptions are reported automatically.

ASP.NET Core#

Terminal
dotnet add package Sentry.AspNetCore
Program.cs
var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseSentry(options =>
{
    options.Dsn = "https://<public-key>@www.bugzor.com/<project-id>";
    options.SendDefaultPii = true; // include the user and IP ("users affected")
});

var app = builder.Build();
app.MapGet("/", () => "ok");
app.Run();

Or set the DSN in appsettings.json:

appsettings.json
{
  "Sentry": {
    "Dsn": "https://<public-key>@www.bugzor.com/<project-id>",
    "SendDefaultPii": true
  }
}

Unhandled exceptions from requests are reported with the request details. ILogger errors become events, and lower levels become breadcrumbs.

Add context#

C#
SentrySdk.ConfigureScope(scope =>
{
    scope.User = new SentryUser { Id = "42", Email = "ann@example.com" };
    scope.SetTag("component", "checkout");
});

SentrySdk.AddBreadcrumb("Signed in", category: "auth");

Filter events#

C#
options.SetBeforeSend((sentryEvent, hint) =>
    sentryEvent.Tags.ContainsKey("healthcheck") ? null : sentryEvent);

Dropped events are never sent and don’t count towards your limits.

Other platforms#

The same DSN works with Sentry.Maui, Sentry.Extensions.Logging, Sentry.Serilog and Sentry.NLog.

Something unclear or out of date? Tell us.