Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serilog-contrib/serilog-sinks-sentry
A Sentry sink for Serilog
https://github.com/serilog-contrib/serilog-sinks-sentry
sentry serilog
Last synced: 4 months ago
JSON representation
A Sentry sink for Serilog
- Host: GitHub
- URL: https://github.com/serilog-contrib/serilog-sinks-sentry
- Owner: serilog-contrib
- License: mit
- Created: 2017-08-26T17:01:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-09T21:28:28.000Z (over 2 years ago)
- Last Synced: 2024-04-10T15:06:32.703Z (11 months ago)
- Topics: sentry, serilog
- Language: C#
- Homepage:
- Size: 587 KB
- Stars: 34
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - serilog-sinks-sentry - A Sentry sink for Serilog (C# #)
README
# Serilog.Sinks.Sentry
## Note
> This is an unofficial library based on [the old Raven SDK](https://github.com/getsentry/raven-csharp/), 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**](https://github.com/getsentry/sentry-dotnet) and [**the Serilog sink**](https://www.nuget.org/packages/Sentry.Serilog).[](https://ci.appveyor.com/project/olsh/serilog-sinks-sentry)
[](https://sonarcloud.io/dashboard?id=serilog-sinks-sentry)| | Package |
| ------------- | ------------- |
| Serilog.Sinks.Sentry | [](https://www.nuget.org/packages/Serilog.Sinks.Sentry/) |
| Serilog.Sinks.Sentry.AspNetCore | [](https://www.nuget.org/packages/Serilog.Sinks.Sentry.AspNetCore/) |A Sentry sink for Serilog.
## Installation
The library is available as a [Nuget package](https://www.nuget.org/packages/Serilog.Sinks.Sentry/).
```
Install-Package Serilog.Sinks.Sentry
```## Demos
You can find demo .NET Core apps [here](demos/).
## Get started
### Adding Sentry sink
```csharp
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.");
```### Data scrubbing
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:
```csharp
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](demos/SentryWeb/Startup.cs) and the [example implementation of a scrubber](demos/SentryWeb/Scrubbing/CustomLogScrubber.cs) .
### Capturing HttpContext (ASP.NET Core)
In order to capture a user, request body and headers, some additional steps are required.
Install the [additional sink](https://www.nuget.org/packages/Serilog.Sinks.Sentry.AspNetCore/) for ASP.NET Core
```
Install-Package Serilog.Sinks.Sentry.AspNetCore
```Specify custom HttpContext destructing policy
```csharp
var log = new LoggerConfiguration()
.WriteTo.Sentry("Sentry DSN")
.Enrich.FromLogContext()// Add this two lines to the logger configuration
.Destructure.With()
.Filter.ByExcluding(e => e.Exception?.CheckIfCaptured() == true).CreateLogger();
```Add Sentry context middleware in Startup.cs
````csharp
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Add this line
app.AddSentryContext();// Other stuff
}
````