Serilog.Sinks.SentrySDK.AspNetCore.6
1.0.5
See the version list below for details.
dotnet add package Serilog.Sinks.SentrySDK.AspNetCore.6 --version 1.0.5
NuGet\Install-Package Serilog.Sinks.SentrySDK.AspNetCore.6 -Version 1.0.5
<PackageReference Include="Serilog.Sinks.SentrySDK.AspNetCore.6" Version="1.0.5" />
paket add Serilog.Sinks.SentrySDK.AspNetCore.6 --version 1.0.5
#r "nuget: Serilog.Sinks.SentrySDK.AspNetCore.6, 1.0.5"
// Install Serilog.Sinks.SentrySDK.AspNetCore.6 as a Cake Addin #addin nuget:?package=Serilog.Sinks.SentrySDK.AspNetCore.6&version=1.0.5 // Install Serilog.Sinks.SentrySDK.AspNetCore.6 as a Cake Tool #tool nuget:?package=Serilog.Sinks.SentrySDK.AspNetCore.6&version=1.0.5
Serilog.Sinks.SentrySDK
A Serilog sink for Sentry that simplifies error and log management in your applications.
Based on serilog-contrib/serilog-sinks-sentry
Project Status
Available Packages
Package | Nuget | |
---|---|---|
Serilog.Sinks.SentrySDK | Package Link | |
Serilog.Sinks.SentrySDK.AspNetCore | Package Link |
Q1 2024
I moving the package to my personal account
Installation
The library is available as a Nuget package.
You can install it with the following command:
dotnet add package Serilog.Sinks.SentrySDK
Install-Package Serilog.Sinks.SentrySDK
Demos
Demos demonstrating how to use this library can be found here.
Getting Started
Adding the Sentry Sink
Add the Sentry sink to your Serilog logger configuration, so that the logs will be sent to your Sentry instance. The Sentry DSN must be provided.
You can also configure Serilog using a JSON configuration. Here's a sample:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"Serilog": {
"Using": [
"Serilog.Sinks.SentrySDK"
],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "Sentry",
"Args": {
"dsn": "",
"sendDefaultPii": true,
"maxBreadcrumbs": 200,
"maxQueueItems": 100,
"debug": true,
"diagnosticLevel": "Error",
"environment": "Development",
"operationName": "SentryConsole",
"release": "1.0.5",
"serverName": "SentryConsole",
"dist": "SentryConsole",
"tags": "SentryConsole=SentryConsole",
"tracesSampleRate": 1.0,
"tracesSampler": "AlwaysSample",
"stackTraceMode": "Enhanced",
"isGlobalModeEnabled": true,
"sampleRate": 1.0,
"attachStacktrace": true,
"autoSessionTracking": true,
"enableTracing": true
}
}
],
"Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"],
"Properties": {
"Application": "Sample"
}
}
}
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var log = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.FromLogContext()
.CreateLogger();
// By default, only messages with level errors and higher are captured
log.Error("This error goes to Sentry.");
Data Scrubbing
Data scrubbing allows you to sanitize your logs before they are sent to Sentry. This can be useful for removing sensitive information.
To use it, provide a custom IScrubber
implementation when setting up the Sentry Sink:
var log = new LoggerConfiguration()
.WriteTo.Sentry("Sentry DSN", dataScrubber: new MyDataScrubber())
.Enrich.FromLogContext()
.CreateLogger();
Capturing HttpContext (ASP.NET Core)
To include user, request body, and header information in the logs, some additional setup is required.
First, install the ASP.NET Core sink with the command:
dotnet add package Serilog.Sinks.SentrySDK.AspNetCore
Install-Package Serilog.Sinks.SentrySDK.AspNetCore
Then, update your logger configuration to include a custom HttpContextDestructingPolicy
:
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();
Finally, add the Sentry context middleware to your Startup.cs
:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Add this line
app.AddSentryContext();
// Other stuff
}
With these steps, your logs will include detailed information about the HTTP context of the requests.
Sentry SDK
Properties
BackgroundWorker
: A property that gets or sets the worker used by the client to pass envelopes.SentryScopeStateProcessor
: A property to get or set the Scope state processor.SendDefaultPii
: A property to get or set whether to include default Personal Identifiable Information.NetworkStatusListener
: A property to get or set a mechanism to convey network status to the caching transport.ServerName
: A property to get or set the name of the server running the application.AttachStacktrace
: A property to get or set whether to send the stack trace of an event captured without an exception.IsEnvironmentUser
: A property to get or set whether to report the System.Environment.UserName as the User affected in the event.SampleRate
: A property to get or set the optional sample rate.ShutdownTimeout
: A property to get or set how long to wait for events to be sent before shutdown.MaxBreadcrumbs
: A property to get or set the maximum breadcrumbs.MaxQueueItems
: A property to get or set the maximum number of events to keep while the worker attempts to send them.BeforeBreadcrumb
: A property to get or set a callback function to be invoked when a breadcrumb is about to be stored.BeforeSendTransaction
: A property to get or set a callback to invoke before sending a transaction to Sentry.MaxCacheItems
: A property to get or set the maximum number of events to keep in cache.Dsn
: A property to get or set the Data Source Name of a given project in Sentry.Environment
: A property to get or set the environment the application is running.Distribution
: A property to get or set the distribution of the application, associated with the release set inSentryOptions.Release
.Release
: A property to get or set the release information for the application.BeforeSend
: A property to get or set a callback to invoke before sending an event to Sentry.
Methods
AddJsonConverter(JsonConverter converter)
: A method to add aJsonConverter
to be used when serializing or deserializing objects to JSON with the SDK.SetBeforeBreadcrumb(Func<Breadcrumb, Breadcrumb?> beforeBreadcrumb)
: A method to set a callback function to be invoked when a breadcrumb is about to be stored.SetBeforeBreadcrumb(Func<Breadcrumb, Hint, Breadcrumb?> beforeBreadcrumb)
: Another overload ofSetBeforeBreadcrumb
method that accepts aHint
.SetBeforeSend(Func<SentryEvent, SentryEvent?> beforeSend)
: A method to configure a callback function to be invoked before sending an event to Sentry.SetBeforeSend(Func<SentryEvent, Hint, SentryEvent?> beforeSend)
: Another overload ofSetBeforeSend
method that accepts aHint
.SetBeforeSendTransaction(Func<Transaction, Transaction?> beforeSendTransaction)
: A method to configure a callback to invoke before sending a transaction to Sentry.SetBeforeSendTransaction(Func<Transaction, Hint, Transaction?> beforeSendTransaction)
: Another overload ofSetBeforeSendTransaction
method that accepts aHint
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Sentry (>= 3.34.0)
- Sentry.Serilog (>= 3.33.1)
- Serilog.Settings.Configuration (>= 7.0.0)
- Serilog.Sinks.SentrySDK (>= 1.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.