diff --git a/docs/platforms/dotnet/guides/extensions-logging/index.mdx b/docs/platforms/dotnet/guides/extensions-logging/index.mdx index 54e397b2a4290f..a45cde0a45c698 100644 --- a/docs/platforms/dotnet/guides/extensions-logging/index.mdx +++ b/docs/platforms/dotnet/guides/extensions-logging/index.mdx @@ -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 @@ -89,7 +89,8 @@ Example using `appsettings.json`: { "Logging": { "LogLevel": { - "Default": "Debug" + "Default": "Debug", + "Microsoft": "Warning" } }, "Sentry": { @@ -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` @@ -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 @@ -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. + + + +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). + + #### TagFilters diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index 767c129dc6ecd9..260b4794ef35ae 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -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 @@ -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: @@ -67,6 +87,22 @@ Log.Logger = new LoggerConfiguration() .CreateLogger(); ``` +```json {filename:appsettings.json} +{ + "Serilog": { + "Using": [ "Sentry.Serilog" ], + "WriteTo": [ + { + "Name": "Sentry", + "Args": { + "dsn": "___PUBLIC_DSN___" + } + } + ] + } +} +``` + 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.