Skip to content
← All articles
Project introduction

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

Listen to the audio story

When a log line becomes an error report · 2:04 · AI-written script, synthetic voices

Transcript

Ava: A log line says something happened. But to fix an error, you also need the exception, the release, the environment and what the request looked like. How do you get both in one place?

Andrew: I'd guess you wire your logging to your error tracker.

Ava: Exactly, and that's Serilog.Sinks.SentrySDK, a .NET package from Antoine. It's based on an existing sink from the Serilog community, and it connects Serilog logging to Sentry error reporting.

Andrew: What's a sink, in this world?

Ava: The place logs flow into. Think of Serilog as a river of log events, and a sink as a channel that carries them somewhere. Here, the channel leads to Sentry.

Andrew: So how is it built?

Ava: The sink receives each log event and hands it to a small wrapper around the Sentry SDK. The wrapper covers three jobs: capturing messages, capturing exceptions, and creating transactions. Because that boundary is small, it's easy to swap out in tests.

Andrew: Anything to know about setup?

Ava: The sink starts Sentry itself, so you decide once who owns initialization, and it needs a real D S N. Install it with dotnet add package, and the repo has console and ASP.NET Core demos to copy from.

Andrew: And for web apps?

Ava: A companion project brings request context. It has a request adapter, a destructuring policy, exception extensions and middleware, so errors arrive with the details that help you investigate.

Andrew: Can you tweak what's sent?

Ava: Yes. There are advanced options and a beforeSend callback to filter or enrich events, and the code documents how that fits with the sink's own event mapping.

Andrew: Which versions does it support?

Ava: Two main packages target net6 and net10, plus separate variants for each. A live NuGet badge shows the download count.

Andrew: And it's checked?

Ava: The README documents xUnit tests, coverage collection and formatting checks.

Andrew: So logs and errors finally tell one story. The full write-up has the diagram of the adapter.

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.