Skip to content
← All articles
Project introduction

Serilog.Sinks.SentrySDK: connecting structured logs to error reporting

Listen to the audio story

From a log line to a useful error · 1:55 · AI-written script, synthetic voices

Transcript

Ava: A log line says something happened. It rarely says enough to fix it.

Andrew: Right, you get a message at three in the morning and no idea which release or environment it came from.

Ava: That gap is what Serilog dot Sinks dot SentrySDK is for. It's a .NET library by Antoine that connects Serilog logging with Sentry error events, so an error carries its exception, release, environment and request context.

Andrew: Did he start from scratch?

Ava: No, it's based on an existing community project, serilog-sinks-sentry. And Antoine points out that its GitHub stars measure interest in this repository only, not overall Serilog or Sentry adoption.

Andrew: How does it work inside?

Ava: A sink receives each Serilog event and hands it to a small wrapper around the official Sentry SDK. That wrapper handles messages, exceptions and transactions, and it also makes the SDK easy to swap out in tests.

Andrew: Any gotcha for people adopting it?

Ava: Yes, initialization. The sink sets up Sentry itself, and the README warns against calling Sentry's init a second time in the same process. In a web app that already initializes monitoring, decide who owns it first.

Andrew: What about request data? That sounds sensitive.

Ava: It is. A companion ASP.NET Core package adds request context, but the post says to choose deliberately what leaves your app and to review personal data settings and filtering. There's also a before-send callback for filtering or enriching events.

Andrew: And what do we actually know about quality?

Ava: The README documents unit tests, coverage collection and formatting checks. Antoine doesn't claim to have rerun them, and he doesn't invent a coverage number. The package targets net six and net ten.

Andrew: Install is one command?

Ava: dotnet add package, yes. The full post has the architecture diagram and links to the demos.

Serilog Sentry SDK package artwork from src/assets in the repository
Table of contents

A log line tells you that something happened. An error event becomes useful when it also carries the exception, release, environment, and request context needed to investigate it. Serilog.Sinks.SentrySDK connects those two views.

This project is based on serilog-contrib/serilog-sinks-sentry. Its own GitHub stars measure interest in this repository, not total Serilog or Sentry adoption.

1. The adapter boundary

flowchart TD
  A["Application"] --> L["Serilog LogEvent"]
  L --> S["SentrySink"]
  S --> W["ISentrySdkWrapper"]
  W --> SDK["Sentry .NET SDK"]
  SDK --> E["Sentry event reporting"]
  C["ASP.NET Core context middleware"] -. context .-> S

SentrySink.cs[1] implements ILogEventSink and IDisposable. An ISentrySdkWrapper abstracts message capture, exception capture, and transaction creation. That boundary also makes SDK interactions replaceable in tests.

2. Initialize once

The sink configures Sentry internally. Its constructor rejects an empty DSN, prepares options, and owns an initialization handle. The README warns against adding a second independent SentrySdk.Init in the same process.

This is easy to miss in a web application that already initializes monitoring elsewhere. Decide who owns initialization before adding the sink.

dotnet add package Serilog.Sinks.SentrySDK

The repository includes console and ASP.NET Core demos. Use their configuration examples for the installed version rather than copying an arbitrary overload from an older package.

3. Context needs deliberate handling

The companion ASP.NET Core project contains a request adapter, destructuring policy, exception extensions, and context middleware. Request context helps diagnose failures, but it should be selected deliberately. Review PII settings and filtering before sending application data.

The sink exposes advanced options and a beforeSend callback. Its code documents callback ordering around EventId mapping; that is useful when filtering or enriching events without overwriting the sink’s own mapping.

4. Packages and adoption

The current README describes two main package IDs that target net6.0 and net10.0, plus separate .6 and .10 variants. This describes package targets, not a recommendation about runtime support lifecycles.

NuGet total downloads for Serilog.Sinks.SentrySDK[4]

The badge is a live download count for that package ID. It excludes the separately published variants, and downloads are not the same as active installations. The dated repository snapshot above is kept separate.

5. What the checks establish

The README documents xUnit tests, coverage collection, and formatting checks. CI and release badges are linked evidence; this article does not claim those checks were rerun here or invent a coverage percentage.

6. Sources

References

  1. antoinebou12. (). SentrySink.cs. [Source file or documentation] github.com.
  2. antoinebou12. (). Serilog.Sinks.SentrySDK. [Software repository] github.com.
  3. antoinebou12. (). Console and web demos. [Source file or documentation] github.com.
  4. NuGet package statistics. (). [Web page] www.nuget.org.

References use this article’s publication date.