Package | |
---|---|
Serilog.Sinks.Sentry | |
Serilog.Sinks.Sentry.AspNetCore |
A Sentry sink for Serilog.
The library is available as a Nuget package.
Install-Package Serilog.Sinks.Sentry
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.");
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
}
At the moment only .NET Framework and .NET Core 2.0 are supported.