Skip to content

jrottmann/serilog-sinks-sentry

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Sentry sink for Serilog

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 69.6%
  • PowerShell 30.4%