This is an unofficial library based on the old Raven SDK, the only use case for this is legacy projects (.NET Framework 4.5 to 4.6.0)
For .NET Framework 4.6.1, .NET Core 2.0, Mono 5.4 or higher, please use the new SDK and the Serilog sink.
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
You can find demo .NET Core apps here.
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.");
Some of the logged content might contain sensitive data and should therefore not be sent to Sentry. When setting up the Sentry Sink it is possible to provide a custom IScrubber
implementation which will be passed the serialized data that is about to be sent to Sentry for scrubbing / cleaning.
Adding a scrubber would look like this:
var log = new LoggerConfiguration()
.WriteTo.Sentry("Sentry DSN", dataScrubber: new MyDataScrubber())
.Enrich.FromLogContext()
.CreateLogger();
MyDataScrubber
has to implement the interface SharpRaven.Logging.IScrubber
. Check the Web Demo Startup.cs for further details and the example implementation of a scrubber .
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
}