From 2cfb648f2f4eda0f2fa0c51121db95f17873445e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Thu, 21 Aug 2025 23:03:13 +0200 Subject: [PATCH 1/4] docs(dotnet/logs): add Logs for the Serilog SDK --- docs/platforms/dotnet/common/logs/index.mdx | 1 - .../explore/logs/getting-started/index.mdx | 5 ++ .../logs/integrations/dotnet.mdx | 1 + platform-includes/logs/options/dotnet.mdx | 12 ++++- .../logs/requirements/dotnet.mdx | 8 +++- platform-includes/logs/setup/dotnet.mdx | 15 +++++- platform-includes/logs/usage/dotnet.mdx | 46 +++++++++++++++---- 7 files changed, 76 insertions(+), 12 deletions(-) diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx index ed67f09446c9e..df9063d7916a4 100644 --- a/docs/platforms/dotnet/common/logs/index.mdx +++ b/docs/platforms/dotnet/common/logs/index.mdx @@ -7,7 +7,6 @@ notSupported: - dotnet.google-cloud-functions - dotnet.log4net - dotnet.nlog - - dotnet.serilog - dotnet.xamarin --- diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index 36e31497155b3..17add3af9e009 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -268,6 +268,11 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s label="Microsoft.Extensions.Logging" url="/platforms/dotnet/guides/extensions-logging/logs/" /> +- ## Upcoming SDKs diff --git a/platform-includes/logs/integrations/dotnet.mdx b/platform-includes/logs/integrations/dotnet.mdx index e39212ae4540c..7dfdde786c31c 100644 --- a/platform-includes/logs/integrations/dotnet.mdx +++ b/platform-includes/logs/integrations/dotnet.mdx @@ -2,5 +2,6 @@ Available integrations: - [ASP.NET Core](/platforms/dotnet/guides/aspnetcore/logs/) - [.NET Multi-platform App UI (.NET MAUI)](/platforms/dotnet/guides/maui/logs/) - [Microsoft.Extensions.Logging](/platforms/dotnet/guides/extensions-logging/logs/) +- [Serilog](/platforms/dotnet/guides/serilog/logs/) If there's an integration you would like to see, open a [new issue on GitHub](https://github.com/getsentry/sentry-dotnet/issues/new/choose). diff --git a/platform-includes/logs/options/dotnet.mdx b/platform-includes/logs/options/dotnet.mdx index 54dc0fb21f41c..59324b86c013d 100644 --- a/platform-includes/logs/options/dotnet.mdx +++ b/platform-includes/logs/options/dotnet.mdx @@ -1,6 +1,16 @@ #### Experimental.EnableLogs -Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs, as well as logging integrations via the `ILogger` API. + +Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs. + + + +Set to `true` in order to enable the logging integration via the `ILogger` API. + + + +Set to `true` in order to enable the logging integration via the `Log`/`Logger` APIs. + #### Experimental.SetBeforeSendLog diff --git a/platform-includes/logs/requirements/dotnet.mdx b/platform-includes/logs/requirements/dotnet.mdx index 0df8ad43b5734..c8727f8f7f4e1 100644 --- a/platform-includes/logs/requirements/dotnet.mdx +++ b/platform-includes/logs/requirements/dotnet.mdx @@ -1 +1,7 @@ -Logs for .NET are supported in Sentry .NET SDK version `5.14.0` and above. + +Logs for are supported in Sentry SDK version `5.14.0` and above. + + + +Logs for are supported in Sentry SDK version `5.15.0` and above. + diff --git a/platform-includes/logs/setup/dotnet.mdx b/platform-includes/logs/setup/dotnet.mdx index 9ebb12aaaa741..29da2b2c311d4 100644 --- a/platform-includes/logs/setup/dotnet.mdx +++ b/platform-includes/logs/setup/dotnet.mdx @@ -1,6 +1,6 @@ To enable logging, you need to initialize the SDK with the `Experimental.EnableLogs` option set to `true`. - + ```csharp SentrySdk.Init(options => @@ -53,3 +53,16 @@ SentrySdk.Init(options => ``` + + + +```csharp +.WriteTo.Sentry(options => +{ + options.Dsn = "___PUBLIC_DSN___"; + // Enable logs to be sent to Sentry + options.Experimental.EnableLogs = true; +}); +``` + + diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index a0c8515390693..4e2674b0d68a5 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -1,4 +1,4 @@ - + Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Experimental.Logger` APIs. @@ -27,12 +27,12 @@ The `LoggerExtensions` extension methods expose various overloads that you can u | Microsoft.Extensions.Logging.LogLevel | Sentry.SentryLogLevel | Sentry Logs UI Severity | | --- | --- | --- | -| Trace | Trace | TRACE | -| Debug | Debug | DEBUG | -| Information | Info | INFO | -| Warning | Warning | WARN | -| Error | Error | ERROR | -| Critical | Fatal | FATAL | +| Trace | Trace | trace | +| Debug | Debug | debug | +| Information | Info | info | +| Warning | Warning | warn | +| Error | Error | error | +| Critical | Fatal | fatal | These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column. @@ -55,7 +55,37 @@ Sentry Structured Logs also work with [High-performance logging in .NET](https:/ - + + +Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the _Serilog_ APIs. + +The static `Log` and instance `Logger` types expose various methods that you can use to log messages at six different log levels automatically mapped to Sentry's severity: + +| Serilog.Events.LogEventLevel | Sentry.SentryLogLevel | Sentry Logs UI Severity | +| --- | --- | --- | +| Verbose | Trace | trace | +| Debug | Debug | debug | +| Information | Info | info | +| Warning | Warning | warn | +| Error | Error | error | +| Fatal | Fatal | fatal | + +These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column. + +```csharp +using (LogContext.PushProperty("Version", 5150)) +{ + Log.Information("A simple log message"); + Log.Error("A {Parameter} log message", "formatted"); + Log.ForContext("Property", "Value").Warning("Message with Property"); +} +``` + +The _Enrichments_ of _log events_ are attached as attributes to the logs, alongside a set of default attributes automatically provided by the SDK. + + + + The SDK automatically provides a set of default attributes attached to your logs. Additionally, you can attach custom attributes via a delegate. From 38a7ed1b9fe60444978d0de1a7e2e4f6f7759ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Thu, 21 Aug 2025 23:09:29 +0200 Subject: [PATCH 2/4] docs(dotnet/logs): update APIs --- platform-includes/logs/usage/dotnet.mdx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index 4e2674b0d68a5..ccd9f96bf59b0 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -8,7 +8,7 @@ These properties will be sent to Sentry, and can be searched from within the Log ```csharp SentrySdk.Experimental.Logger.LogInfo("A simple log message"); -SentrySdk.Experimental.Logger.LogError("A {0} log message", ["formatted"]); +SentrySdk.Experimental.Logger.LogError("A {0} log message", "formatted"); ``` @@ -91,16 +91,12 @@ The SDK automatically provides a set of default attributes attached to your logs Additionally, you can attach custom attributes via a delegate. ```csharp -SentrySdk.Experimental.Logger.LogWarning("A log message with additional attributes.", [], static log => +SentrySdk.Experimental.Logger.LogWarning(static log => { log.SetAttribute("my.attribute", "value"); -}); +}, "A log message with additional attributes."); ``` - -Please note that we will revise the API shape to set custom attributes during the experimental phase of the feature. - - Supported attribute types are: - Textual: `string` and `char` - Logical: `bool` From 575dee046a68c6904629a4845b3fc150b2709e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 25 Aug 2025 18:29:19 +0200 Subject: [PATCH 3/4] docs(dotnet/logs): update Serilog guide --- docs/platforms/dotnet/guides/serilog/index.mdx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index bb96fcf6236a7..b9fc0ad6c85aa 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -9,7 +9,8 @@ Sentry provides an integration with `Serilog` through the [Sentry.Serilog NuGet ## Overview of the features - Store log messages as breadcrumbs -- Send events to sentry +- Send events to Sentry +- Send structured logs 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](enriching-events/scopes/). @@ -19,6 +20,8 @@ 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`. +Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). + ## Install Add the Sentry dependency: From 5d8d51fc2b3c55e437bc2a0af1402a06abfc4c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:44:22 +0200 Subject: [PATCH 4/4] docs(dotnet/logs): update API examples for v5.16.0 --- platform-includes/logs/options/dotnet.mdx | 2 +- platform-includes/logs/requirements/dotnet.mdx | 2 +- platform-includes/logs/usage/dotnet.mdx | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/platform-includes/logs/options/dotnet.mdx b/platform-includes/logs/options/dotnet.mdx index 59324b86c013d..ab726ffe4f38f 100644 --- a/platform-includes/logs/options/dotnet.mdx +++ b/platform-includes/logs/options/dotnet.mdx @@ -1,7 +1,7 @@ #### Experimental.EnableLogs -Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs. +Set to `true` in order to enable the `SentrySdk.Logger` APIs. diff --git a/platform-includes/logs/requirements/dotnet.mdx b/platform-includes/logs/requirements/dotnet.mdx index c8727f8f7f4e1..3f0941afd2f20 100644 --- a/platform-includes/logs/requirements/dotnet.mdx +++ b/platform-includes/logs/requirements/dotnet.mdx @@ -3,5 +3,5 @@ Logs for are supported in Sentry S -Logs for are supported in Sentry SDK version `5.15.0` and above. +Logs for are supported in Sentry SDK version `5.16.0` and above. diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index ccd9f96bf59b0..6eb0bcaf692ec 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -1,14 +1,14 @@ -Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Experimental.Logger` APIs. +Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Logger` APIs. -The `SentrySdk.Experimental.Logger` instance exposes six methods that you can use to log messages at different log levels: `Trace`, `Debug`, `Info`, `Warning`, `Error`, and `Fatal`. +The `SentrySdk.Logger` instance exposes six methods that you can use to log messages at different log levels: `Trace`, `Debug`, `Info`, `Warning`, `Error`, and `Fatal`. These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column. ```csharp -SentrySdk.Experimental.Logger.LogInfo("A simple log message"); -SentrySdk.Experimental.Logger.LogError("A {0} log message", "formatted"); +SentrySdk.Logger.LogInfo("A simple log message"); +SentrySdk.Logger.LogError("A {0} log message", "formatted"); ``` @@ -91,7 +91,7 @@ The SDK automatically provides a set of default attributes attached to your logs Additionally, you can attach custom attributes via a delegate. ```csharp -SentrySdk.Experimental.Logger.LogWarning(static log => +SentrySdk.Logger.LogWarning(static log => { log.SetAttribute("my.attribute", "value"); }, "A log message with additional attributes.");