Serilog

Sentry provides an integration with Serilog through the Sentry.Serilog NuGet package.

Add the Sentry dependency:

Copied
Install-Package Sentry.Serilog -Version 4.3.0

This package extends Sentry main SDK. That means that besides the logging related features, through this package you'll also get access to all API and features available in the main Sentry SDK.

  • Store log messages as breadcrumbs
  • Send events to sentry

Two separate settings define the minimum log level to keep the log entry as a Breadcrumb and to send an Event to Sentry. The events include any stored breadcrumb on that scope.

By default, any message with log level Information or higher will be kept as a Breadcrumb.

The default value to report a log entry as an event to Sentry is Error.

This means that out of the box, any LogError call will create an Event which will include all log messages of level Information, Warning and also Error and Critical.

You can configure the Sentry Serilog sink as follows:

Copied
Log.Logger = new LoggerConfiguration()
  .WriteTo.Sentry(o =>
  {
    // Debug and higher are stored as breadcrumbs (default is Information)
    o.MinimumBreadcrumbLevel = LogEventLevel.Debug;
    // Warning and higher is sent as event (default is Error)
    o.MinimumEventLevel = LogEventLevel.Warning;
  })
  .CreateLogger();

It's also possible to initialize the SDK through the Serilog integration. This is useful when the Serilog is the only integration being used in your application. To initialize the Sentry SDK through the Serilog integration, provide it with the DSN:

Copied
Log.Logger = new LoggerConfiguration()
  .WriteTo.Sentry(o => o.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/0")
  .CreateLogger();

A LogLevel which indicates the minimum level a log message has to be included as a breadcrumb. By default this value is Information.

A LogLevel which indicates the minimum level a log message has to be sent to Sentry as an event. By default this value is Error.

Whether or not this integration should initialize the SDK. If you intend to call SentrySdk.Init yourself you should set this flag to false.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").