Skip to content

Latest commit

 

History

History
68 lines (50 loc) · 2.11 KB

README.md

File metadata and controls

68 lines (50 loc) · 2.11 KB

Serilog.Sinks.Sentry

Build status Quality Gate

Package
Serilog.Sinks.Sentry NuGet
Serilog.Sinks.Sentry.AspNetCore NuGet

A Sentry sink for Serilog.

Installation

The library is available as a Nuget package.

Install-Package Serilog.Sinks.Sentry

Get started

Adding Sentry sink

var log = new LoggerConfiguration()
    .WriteTo.Sentry("Sentry DSN")
    .Enrich.FromLogContext()
    .CreateLogger();

// By default, only messages with level errors and higher are captured
log.Error("This error goes to Sentry.");

Capturing HttpContext (ASP.NET Core)

In order to capture a user, request body and headers, some additional steps are required.

Install the additional sink for ASP.NET Core

Install-Package Serilog.Sinks.Sentry.AspNetCore

Specify custom HttpContext destructing policy

var log = new LoggerConfiguration()
    .WriteTo.Sentry("Sentry DSN")
    .Enrich.FromLogContext()

    // Add this two lines to the logger configuration
    .Destructure.With<HttpContextDestructingPolicy>()
    .Filter.ByExcluding(e => e.Exception?.CheckIfCaptured() == true)

    .CreateLogger();

Add Sentry context middleware in Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // Add this line
    app.AddSentryContext();

    // Other stuff
}

Known issues

At the moment only .NET Framework and .NET Core 2.0 are supported.