Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions docs/platforms/dotnet/guides/extensions-logging/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ By default, any message with log level `Information` or higher will be kept as a

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`.
This means that out of the box, any `LogError` call will create an `Event` which will include breadcrumbs for all prior log messages of level `Information`, `Warning`, `Error` and `Critical`.

Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/).
Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). Filtering to control the minimum log level to capture should be done [via `Microsoft.Extensions.Logging` configuration](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging/overview?tabs=command-line#how-filtering-rules-are-applied).

## Install

Expand Down Expand Up @@ -89,7 +89,8 @@ Example using `appsettings.json`:
{
"Logging": {
"LogLevel": {
"Default": "Debug"
"Default": "Debug",
"Microsoft": "Warning"
}
},
"Sentry": {
Expand All @@ -102,7 +103,7 @@ Example using `appsettings.json`:
}
```

Above we set the application wide minimum log level to `Debug`. Sentry specific settings are set under the `Sentry` property. Options are documented below.
Above we set the application wide minimum log level to `Debug` and we configure a minimum log level for Microsoft specific logs to `Warning`. Sentry specific settings are set under the `Sentry` property. Options are documented below.

#### Through `ILoggerFactory`

Expand All @@ -117,6 +118,7 @@ using (var loggerFactory = new LoggerFactory()
```

This approach doesn't include any of the framework's configuration system. Since the DSN is being provided via parameter, the SDK will be initialized.

More settings can be passed via the callback configuring the `SentryOptions`.

## Options and Initialization
Expand Down Expand Up @@ -153,7 +155,13 @@ Whether or not this integration should initialize the SDK. If you intend to call

#### Filters

A list of filters which are invoked before processing any log message. This allows you to inspect the details of the log entry before they become a `Breadcrumb` or an `Event` with full access to the `Microsoft.Extensions.Logging` data.
A list of filters which are invoked before processing log messages. This allows you to inspect the details of the log entry before they become a `Breadcrumb` or an `Event` with full access to the `Microsoft.Extensions.Logging` data.

<Alert title="✨ Note">

These filters only apply to breadcrumbs and events. They don't control which logs will be captured as structured logs in Sentry. That can be controlled independently using the [filtering capabilities built into `Microsoft.Extensions.Logging`](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging/overview?tabs=command-line#how-filtering-rules-are-applied).

</Alert>

#### TagFilters

Expand Down
40 changes: 38 additions & 2 deletions docs/platforms/dotnet/guides/serilog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ By default, any message with log level `Information` or higher will be kept as a

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`.
This means that out of the box, any `LogError` call will create an `Event` which will include breadcrumbs for all prior log messages of level `Information`, `Warning`, `Error` and `Critical`.

Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/).
Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). You can control which logs are captured using the [Serilog MinimumLogLevel](https://github.com/serilog/serilog/wiki/Configuration-Basics#minimum-level).

## Install

Expand Down Expand Up @@ -58,6 +58,26 @@ Log.Logger = new LoggerConfiguration()
.CreateLogger();
```

```json {filename:appsettings.json}
{
"Serilog": {
"Using": [ "Sentry.Serilog" ],
"MinimumLevel": {
"Default": "Debug"
},
"WriteTo": [
{
"Name": "Sentry",
"Args": {
"minimumBreadcrumbLevel": "Debug",
"minimumEventLevel": "Warning"
}
}
]
}
}
```

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:


Expand All @@ -67,6 +87,22 @@ Log.Logger = new LoggerConfiguration()
.CreateLogger();
```

```json {filename:appsettings.json}
{
"Serilog": {
"Using": [ "Sentry.Serilog" ],
"WriteTo": [
{
"Name": "Sentry",
"Args": {
"dsn": "___PUBLIC_DSN___"
}
}
]
}
}
```

<Alert>

The SDK only needs to be initialized once. If a `DSN` is made available to this integration, by default it **will** initialize the SDK. If you do not wish to initialize the SDK via this integration, set the `InitializeSdk` flag to **false**. Not providing a DSN or leaving it as `null` instructs the integration not to initialize the SDK and unless another integration initializes it or you call `SentrySdk.Init`, the SDK will stay disabled.
Expand Down
Loading