Skip to content

Serilog.Sinks.SentrySDK: Adapting log events to Sentry

Serilog.Sinks.SentrySDK bridges a .NET logging pipeline and the Sentry SDK. The application emits structured log events; a sink adapts that information for Sentry rather than asking every call site to invoke the SDK directly.

Library
  • Updated
  • 2
  • C# · 98.04%
  • MIT
Repository languagesC# 98.04%2

Shares calculated from GitHub Linguist bytes.

Language%Bytes
C#98.04%89,769
PowerShell1.96%1,795

GitHub · README · Language statistics

Overview

Why it exists

Production .NET 6+ Serilog sink bridging structured logging and Sentry error telemetry with zero allocation overhead.

Best fit

Enterprise .NET microservice error observability and distributed trace correlation.

Getting started

These commands come from the repository documentation. They were not run during this review.

README.md · Installation
dotnet add package Serilog.Sinks.SentrySDK
Install-Package Serilog.Sinks.SentrySDK
README.md · Build, run tests, and coverage (local development)
dotnet restore src/Serilog.Sinks.SentrySDK/Serilog.Sinks.SentrySDK.csproj
dotnet build src/Serilog.Sinks.SentrySDK/Serilog.Sinks.SentrySDK.csproj -c Release
dotnet build src/Serilog.Sinks.SentrySDK.AspNetCore/Serilog.Sinks.SentrySDK.AspNetCore.csproj -c Release
dotnet test src/Serilog.Sinks.SentrySDK.Tests/Serilog.Sinks.SentrySDK.Tests.csproj
dotnet test src/Serilog.Sinks.SentrySDK.AspNetCore.Tests/Serilog.Sinks.SentrySDK.AspNetCore.Tests.csproj
README.md · Build, run tests, and coverage (local development)
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=./reports/coverage src/Serilog.Sinks.SentrySDK.Tests/Serilog.Sinks.SentrySDK.Tests.csproj
README.md · Code formatting (dotnet format)
dotnet restore src/Serilog.Sinks.SentrySDK.sln
dotnet format src/Serilog.Sinks.SentrySDK.sln
README.md · Code formatting (dotnet format)
dotnet format src/Serilog.Sinks.SentrySDK.sln --verify-no-changes

Repository references

Excerpts from the repository’s guides, in their original language. Links open the inspected source revision.

Prerequisites and first run

Installation

README.md

The library is available on NuGet as Serilog.Sinks.SentrySDK, or alternate ids Serilog.Sinks.SentrySDK.6 / Serilog.Sinks.SentrySDK.10 if you want a single target framework per package. You can install it with the following command: This package references the Sentry NuGet package (6.3.2), the same major line as the Sentry for .NET documentation. For generic SDK setup (DSN, SendDefaultPii, debug), see the official Quick Start. Initialize the SDK as early as possible so startup failures are reported. This sink calls SentrySdk.Init internally when you configure WriteTo.Sentry with a DSN; avoid calling SentrySdk.Init again for the same process unless you coordinate a single initialization path.
Read the full instructions ↗

Build, run tests, and coverage (local development)

README.md

Prerequisites: .NET SDK 10 to build and run tests. The published libraries multi-target net6.0 and net10.0 (one package includes both under lib/). CI also installs the 6.0.x SDK band so net6.0 targets build cleanly on the runner. From the repository root: Run tests with coverage (same approach as CI, using coverlet): CI uploads Cobertura to Codecov; keep or improve coverage when you change production code.
Read the full instructions ↗

Installation

src/PACKAGE_README.md

Core sink: ASP.NET Core companion (user/request context in logs): Alternate ids (single TFM per package): Serilog.Sinks.SentrySDK.6, Serilog.Sinks.SentrySDK.10, and matching AspNetCore ids — see Available packages. This stack references the Sentry NuGet package (6.3.2), the same major line as Sentry for .NET. For DSN, SendDefaultPii, and debug options, see the Quick Start. Initialize as early as possible so startup failures are reported. This sink calls SentrySdk.Init when you configure WriteTo.Sentry with a DSN; avoid a second SentrySdk.Init in the same process unless you deliberately use one initialization path. Set a valid Sentry DSN in appsettings.json or in code. Without a DSN, the sink throws when the DSN argument is empty. Demos show JSON and programmatic configuration.
Read the full instructions ↗

Getting started

src/PACKAGE_README.md

Add the sink so logs are sent to Sentry. You can use Serilog.Settings.Configuration with JSON: Optional configureSentryOptions and beforeSend on WriteTo.Sentry map to init-time SentryOptions and a chained SetBeforeSend. A fuller argument list and examples are in the repository README — Getting Started.
Read the full instructions ↗

Installation

src/PACKAGE_README_NET6.md

This stack references Sentry (6.3.2). See the Sentry .NET Quick Start. This sink calls SentrySdk.Init when you configure WriteTo.Sentry with a DSN; avoid duplicate in-process initialization.
Read the full instructions ↗
API and integration

Serilog.Sinks.SentrySDK

README.md

A Serilog sink for Sentry that simplifies error and log management in your applications. Based on serilog-contrib/serilog-sinks-sentry
Read the full instructions ↗

Sentry SDK

README.md

Reference for the Sentry .NET SDK SentryOptions (this package references Sentry 6.3.2). The This sink column describes how each member relates to WriteTo.Sentry in this library.
Read the full instructions ↗

Contributing to Serilog.Sinks.SentrySDK

CONTRIBUTING.md

Thank you for helping improve this project. This document describes how we work on GitHub and what we expect in contributions.
Read the full instructions ↗

Serilog.Sinks.SentrySDK

src/PACKAGE_README.md

A Serilog sink for Sentry that simplifies error and log management in your applications. It builds on the Sentry .NET SDK and official Serilog integration. Based on serilog-contrib/serilog-sinks-sentry
Read the full instructions ↗

Sentry SDK options vs this sink

src/PACKAGE_README.md

This package aligns with Sentry .NET 6.3.2. The repository README maps SentryOptions properties and methods to WriteTo.Sentry parameters (large tables): Sentry SDK and Mapping to WriteTo.Sentry. Further reading: Data Management, Structured logs, Migration guide.
Read the full instructions ↗
Development and contributions

Tests and coverage

CONTRIBUTING.md

  • Run tests locally before pushing:
  • CI runs these tests and uploads coverage to Codecov. Prefer new tests for new code paths (e.g. factories, sink behavior, middleware) so coverage does not drop unnecessarily.
Read the full instructions ↗

Demos, build, contributing

src/PACKAGE_README.md

  • Demos: demos/README.md on GitHub
  • Solution and local build/test commands: README — Build, run tests, and coverage
  • CONTRIBUTING.md Full documentation (CI, publishing, formatting): README.md on GitHub.
Read the full instructions ↗
Source documentation

6 documents read from 6 candidates.

Features and components 2

Sink and SDK boundary
SentrySink.cs defines an SDK wrapper interface with capture-message, capture-exception and transaction methods. The wrapper delegates to SentrySdk. This boundary gives tests a substitute for the external SDK calls.
Application context
The source tree separates the sink package from ASP.NET Core integration and tests. Request and user factories adapt HTTP context. Logging configuration and request enrichment therefore have different responsibilities.

Architecture

The components and their connections remain available as text. The diagram adds an interactive view.

System context Context
  1. Application log event
  2. Serilog pipeline
  3. Sentry sink and context
  4. SDK wrapper
  5. Sentry SDK

Links verified in the repository.

Mermaid Interactive diagram (loads on open)

System overview of the components and connections verified in the repository.

Static architecture view for Serilog.Sinks.SentrySDK
Static preview. The interactive diagram replaces it after Mermaid loads.
flowchart LR

subgraph group_logging["Serilog integration"]
  node_sinkconfig["Sink registration"]
  node_sink["Event sink<br/>[SentrySink.cs]"]
end

subgraph group_sentry["Sentry event delivery"]
  node_requestfactory["Request factory"]
  node_userfactory["User factory"]
  node_sentrysdk["Sentry SDK"]
end

subgraph group_web["ASP.NET Core context"]
  node_contextadapter["HTTP adapter"]
  node_middleware["Request middleware"]
  node_destructure["Context destructuring"]
  node_contextcontract["HTTP context contract"]
end

node_app(("Application"))
node_serilog["Serilog pipeline"]
node_sentryservice(("Sentry service"))

node_app -->|"writes events"| node_serilog
node_serilog -->|"configures sink"| node_sinkconfig
node_sinkconfig -->|"creates sink"| node_sink
node_sink -->|"captures events"| node_sentrysdk
node_sentrysdk -.->|"sends telemetry"| node_sentryservice
node_middleware -->|"pushes context"| node_contextadapter
node_middleware -->|"logs exceptions"| node_serilog
node_contextadapter -->|"implements"| node_contextcontract
node_destructure -->|"recognizes context"| node_contextcontract
node_requestfactory -->|"reads request data"| node_contextcontract
node_userfactory -->|"reads user data"| node_contextcontract
node_sink -.->|"uses request context"| node_requestfactory
node_sink -.->|"uses user context"| node_userfactory


class node_sinkconfig,node_sink toneBlue
class node_requestfactory,node_userfactory,node_sentrysdk toneAmber
class node_contextadapter,node_middleware,node_destructure,node_contextcontract toneMint
class node_app,node_serilog,node_sentryservice toneIndigo

A Serilog sink that configures the Sentry SDK and maps log events to messages, exceptions, breadcrumbs and optional traces. The ASP.NET Core package adds request and user context through an HTTP-context adapter.

Components
12
Connections
13
Links supported by code or README
10/13
Text version of the diagram
  • Application log event → Serilog pipeline
  • Serilog pipeline → Sentry sink and context
  • Sentry sink and context → SDK wrapper
  • SDK wrapper → Sentry SDK
Follow one path through the code

Follow an exception-bearing log through the sink and compare it with a message-only event. The wrapper exposes separate capture operations, so a useful test checks the chosen operation and its event data, not only that a call occurred.

Types and file structure

38 declared types, with 12 in the base-relationship overview.

Type diagram
classDiagram
direction TB
class ta0f4fc6d8b31["ISentryRequestFactory"] {
  <<interface>>
  Create()
}
class tab0f434b248f["SentryRequestFactory"] {
  SentryRequestFactory()
  Create()
}
class t94a164d611c8["ISentryRequest"] {
  <<interface>>
}
class t66938c58944a["SentryRequest"] {
}
class td9dd9f1be134["ISentrySdkWrapper"] {
  <<interface>>
  CaptureMessage()
  CaptureException()
  StartTransaction()
}
class t436d77520181["SentrySdkWrapper"] {
  SentrySdkWrapper()
  CaptureMessage()
  CaptureException()
  StartTransaction()
}
class t9aa877270a99["ITransactionService"] {
  <<interface>>
  StartChild()
}
class t7f1535817357["TransactionService"] {
  StartChild()
}
class t53092b4cd27d["SentrySink"] {
  SentrySink()
  Emit()
  EmitWithoutTracing()
  GetBreadcrumbLevel()
}
class t3bef4532763b["SentrySinkExtensions"] {
  Sentry()
}
class t6b344cd3bb4d["Program"] {
  Main()
  ThrowDivideByZeroSecondTier()
  DivByZero()
  ThrowParseExceptionSecondTier()
}
class t0108ee6641d7["HomeController"] {
  Index()
  About()
  Contact()
  Error()
}
ta0f4fc6d8b31 <|.. tab0f434b248f
t94a164d611c8 <|.. t66938c58944a
td9dd9f1be134 <|.. t436d77520181
t9aa877270a99 <|.. t7f1535817357
class bc2d528bdb08a["ILogEventSink"] {
  <<unresolved_base>>
}
t53092b4cd27d ..> bc2d528bdb08a : declared base
class b06fa01e7e2b1["IDisposable"] {
  <<unresolved_base>>
}
t53092b4cd27d ..> b06fa01e7e2b1 : declared base
class bd8f3faa41a98["Controller"] {
  <<unresolved_base>>
}
t0108ee6641d7 ..> bd8f3faa41a98 : declared base

Unresolved bases remain labelled; full signatures are not reconstructed.

Type index

Reference

32 / 32 eligible files read (117 in the tree); 0 oversized, 0 failed reads and 0 syntax diagnostics.

What the scan covers

Known dependency/build folders, credential files and binaries are excluded. The scan covers READMEs, recognized manifests and parser-supported source files.

Linguist statistics cover the whole repository and may include other languages.

File map
flowchart TD
  root["Serilog.Sinks.SentrySDK"]
  f0["src/Serilog.Sinks.SentrySDK/AspNetCoreSentryRequestFactory.cs"]
  root --> f0
  f1["src/Serilog.Sinks.SentrySDK/SentrySink.cs"]
  root --> f1
  f2["src/Serilog.Sinks.SentrySDK/SentrySinkExtensions.cs"]
  root --> f2
  f3["README.md"]
  root --> f3
  f4["demos/README.md"]
  root --> f4
  f5["demos/SentryConsole/Program.cs"]
  root --> f5
  f6["demos/SentryWeb/Program.cs"]
  root --> f6
  f7["demos/SentryWeb/Startup.cs"]
  root --> f7
  f8["src/Serilog.Sinks.SentrySDK.AspNetCore.Tests/AspCoreHttpContextAdapterTests.cs"]
  root --> f8
  f9["src/Serilog.Sinks.SentrySDK.AspNetCore.Tests/ExceptionExtensionsTests.cs"]
  root --> f9
  f10["src/Serilog.Sinks.SentrySDK.AspNetCore.Tests/HttpContextDestructingPolicyTests.cs"]
  root --> f10
  f11["src/Serilog.Sinks.SentrySDK.AspNetCore.Tests/SentrySinkContextMiddlewareTests.cs"]
  root --> f11
  f12["src/Serilog.Sinks.SentrySDK.AspNetCore.Tests/SerilogSentryExtensionsTests.cs"]
  root --> f12
  f13["src/Serilog.Sinks.SentrySDK.AspNetCore/AspCoreHttpContextAdapter.cs"]
  root --> f13
  f14["src/Serilog.Sinks.SentrySDK.AspNetCore/ExceptionExtensions.cs"]
  root --> f14
  f15["src/Serilog.Sinks.SentrySDK.AspNetCore/HttpContextDestructingPolicy.cs"]
  root --> f15

Files to read 3

References