From 7be2901b930d11b2158d8ca6b14328c69b1f73fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Thu, 7 Aug 2025 16:58:00 +0200 Subject: [PATCH 1/7] docs(dotnet/logs): add Logs for the .NET SDK --- docs/platforms/dotnet/common/logs/index.mdx | 45 +++++++++++++ .../explore/logs/getting-started/index.mdx | 13 ++-- .../logs/integrations/dotnet.mdx | 6 ++ platform-includes/logs/options/dotnet.mdx | 47 ++++++++++++++ .../logs/requirements/dotnet.mdx | 1 + platform-includes/logs/setup/dotnet.mdx | 53 ++++++++++++++++ platform-includes/logs/usage/dotnet.mdx | 63 +++++++++++++++++++ 7 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 docs/platforms/dotnet/common/logs/index.mdx create mode 100644 platform-includes/logs/integrations/dotnet.mdx create mode 100644 platform-includes/logs/options/dotnet.mdx create mode 100644 platform-includes/logs/requirements/dotnet.mdx create mode 100644 platform-includes/logs/setup/dotnet.mdx create mode 100644 platform-includes/logs/usage/dotnet.mdx diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx new file mode 100644 index 0000000000000..196400068e4b7 --- /dev/null +++ b/docs/platforms/dotnet/common/logs/index.mdx @@ -0,0 +1,45 @@ +--- +title: Set Up Logs +sidebar_title: Logs +description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry." +sidebar_order: 5600 +notSupported: + - dotnet.google-cloud-functions + - dotnet.log4net + - dotnet.nlog + - dotnet.serilog + - dotnet.xamarin +--- + + + +With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes. + +## Requirements + + + +## Setup + + + +## Usage + + + +## Integrations + + + +## Options + + + + +## Feedback +Sentry Structured Logs is currently in Beta and under active development. +During the experimental phase of support in Sentry's .NET SDK, are are looking forward to your general feedback, both praise and problems, through _Give Feedback_ on Sentry, our [Discord server](https://discord.gg/sentry), or this [GitHub discussion](TODO). +Should you experience bugs or have particular feature request, please open a [new issue on GitHub](https://github.com/getsentry/sentry-dotnet/issues/new/choose). + +## Known issues and upcoming improvement +This [GitHub issue](TODO) tracks all bugs that we are currently fixing and improvement that we will implement during the experimental phase of the feature. diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index 90689a5d05716..71e39b43bf7bd 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -246,6 +246,14 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s - +### .NET + +- + ## Upcoming SDKs We're actively working on adding Log functionality to additional SDKs. Check out these GitHub issues for the latest updates: @@ -260,11 +268,6 @@ We're actively working on adding Log functionality to additional SDKs. Check out label="Elixir" url="https://github.com/getsentry/sentry-elixir/issues/886" /> -- - ](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) API. + +#### Experimental.SetBeforeSendLog(Func) + +To filter logs, or update them before they are sent to Sentry, you can use the `Experimental.SetBeforeSendLog()` option. + +```csharp +options => +{ + options.Dsn = "___PUBLIC_DSN___"; + options.Experimental.EnableLogs = true; + // a callback that is invoked before sending a log to Sentry + options.Experimental.SetBeforeSendLog(static log => + { + // filter out all info logs + if (log.Level is SentryLogLevel.Info) + { + return null; + } + + // filter out logs based on some attribute they have + if (log.TryGetAttribute("suppress", out var attribute) && attribute is true) + { + return null; + } + + // set a custom attribute for all other logs sent to Sentry + log.SetAttribute("my.attribute", "value"); + + return log; + }); +}); +``` + +The callback function set via `Experimental.SetBeforeSendLog()` receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it. + +The log object of type `SentryLog` has the following members: +- `Timestamp` Property: (`DateTimeOffset`) The timestamp of the log. +- `TraceId` Property: (`SentryId`) The trace id of the log. +- `Level` Property: (`SentryLogLevel`) The severity level of the log. Either `Trace`, `Debug`, `Info`, `Warning`, `Error`, or `Fatal`. +- `Message` Property: (`string`) The formatted log message. +- `Template` Property: (`string?`) The parameterized template string. +- `Parameters` Property: (`ImmutableArray>`) The parameters to the template string. +- `ParentSpanId` Property: (`SpanId?`) The span id of the span that was active when the log was collected. +- `TryGetAttribute(string key, out object value)` Method: Gets the attribute value associated with the specified key. Returns `true` if the log contains an attribute with the specified key and it's value is not `null`, otherwise `false`. +- `SetAttribute(string key, object value)` Method: Set a key-value pair of data attached to the log. Supported types are `string`, `bool`, integers up to a size of 64-bit signed, and floating-point numbers up to a size of 64-bit. diff --git a/platform-includes/logs/requirements/dotnet.mdx b/platform-includes/logs/requirements/dotnet.mdx new file mode 100644 index 0000000000000..0df8ad43b5734 --- /dev/null +++ b/platform-includes/logs/requirements/dotnet.mdx @@ -0,0 +1 @@ +Logs for .NET are supported in Sentry .NET SDK version `5.14.0` and above. diff --git a/platform-includes/logs/setup/dotnet.mdx b/platform-includes/logs/setup/dotnet.mdx new file mode 100644 index 0000000000000..f4e152eef9608 --- /dev/null +++ b/platform-includes/logs/setup/dotnet.mdx @@ -0,0 +1,53 @@ +To enable logging, you need to initialize the SDK with the `Experimental.EnableLogs` option set to `true`. + + + +```csharp +SentrySdk.Init(options => +{ + options.Dsn = "___PUBLIC_DSN___"; + // Enable logs to be sent to Sentry + options.Experimental.EnableLogs = true; +}); +``` + + + + + +```csharp {tabTitle:Builder} +.UseSentry(options => +{ + options.Dsn = "___PUBLIC_DSN___"; + // Enable logs to be sent to Sentry + options.Experimental.EnableLogs = true; +}); +``` + + + + + +```csharp {tabTitle:Factory} +.AddSentry(options => +{ + options.Dsn = "___PUBLIC_DSN___"; + // Enable logs to be sent to Sentry + options.Experimental.EnableLogs = true; +}); +``` + + + + + +```json {tabTitle:Configuration} {filename:appsettings.json} + "Sentry": { + "Dsn": "___PUBLIC_DSN___", + "Experimental": { + "EnableLogs": true + } + }, +``` + + diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx new file mode 100644 index 0000000000000..a766e3acabdb6 --- /dev/null +++ b/platform-includes/logs/usage/dotnet.mdx @@ -0,0 +1,63 @@ +Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Experimental.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`. + +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"]); +``` + + +During the experimental phase of the feature, we will provide more method overloads for convenient invocation in common scenarios. +Additionally, we may provide method overloads that are not based on _composite format strings_, but on _interpolated strings_. + + + + +Additionally, when enabled and initialized, the SDK registers a [ILoggerProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerprovider) +that allows sending logs to Sentry via [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) instances resolved through _.NET dependency injection_. + +```csharp +public sealed class MyService(ILogger logger) +{ + public async Task InvokeAsync(HttpContext context) + { + logger.LogInformation("A simple log message"); + await Task.Yield(); + logger.LogError("A {Parameter} log message", "formatted"); + await Task.Delay(TimeSpan.FromSeconds(1)); + logger.LogWarning(new EventId(1, nameof(InvokeAsync)), "Message with EventId"); + } +} +``` + +The `ILogger`'s _CategoryName_, as well as the `EventId` (if provided), are attached as attributes to the logs. + +For more information, see article on [Logging in C# and .NET](https://learn.microsoft.com//dotnet/core/extensions/logging). +Sentry Structured Logs also work with [High-performance logging in .NET](https://learn.microsoft.com/dotnet/core/extensions/high-performance-logging) and [Compile-time logging source generation](https://learn.microsoft.com/dotnet/core/extensions/logger-message-generator) alike. + + + +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 => +{ + log.SetAttribute("my.attribute", "value"); +}); +``` + + +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` +- Integral: `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `long` and `nint` +- Floating-point: `float` and `double` + +Unsupported numeric types such as `ulong`, `nuint`, `decimal`, as well as all other types including `object`, are treated as `string` via `ToString`. From 4f184819cf8c5732229722ccbf40f4b0da8fa2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Fri, 8 Aug 2025 20:48:09 +0200 Subject: [PATCH 2/7] docs(dotnet/logs): remove redundant additions Co-authored-by: Abhijeet Prasad --- docs/platforms/dotnet/common/logs/index.mdx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx index 196400068e4b7..80ab9959c050b 100644 --- a/docs/platforms/dotnet/common/logs/index.mdx +++ b/docs/platforms/dotnet/common/logs/index.mdx @@ -36,10 +36,4 @@ With Sentry Structured Logs, you can send text based log information from your a -## Feedback -Sentry Structured Logs is currently in Beta and under active development. -During the experimental phase of support in Sentry's .NET SDK, are are looking forward to your general feedback, both praise and problems, through _Give Feedback_ on Sentry, our [Discord server](https://discord.gg/sentry), or this [GitHub discussion](TODO). -Should you experience bugs or have particular feature request, please open a [new issue on GitHub](https://github.com/getsentry/sentry-dotnet/issues/new/choose). -## Known issues and upcoming improvement -This [GitHub issue](TODO) tracks all bugs that we are currently fixing and improvement that we will implement during the experimental phase of the feature. From a1cc7daee4df5d3081d771c5eff3e12b166a1eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Tue, 12 Aug 2025 11:06:24 +0200 Subject: [PATCH 3/7] docs(dotnet/logs): fix invalid chevrons in link text --- docs/platforms/dotnet/common/logs/index.mdx | 3 --- platform-includes/logs/options/dotnet.mdx | 8 ++++---- platform-includes/logs/usage/dotnet.mdx | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx index 80ab9959c050b..86dd29732c6cf 100644 --- a/docs/platforms/dotnet/common/logs/index.mdx +++ b/docs/platforms/dotnet/common/logs/index.mdx @@ -34,6 +34,3 @@ With Sentry Structured Logs, you can send text based log information from your a ## Options - - - diff --git a/platform-includes/logs/options/dotnet.mdx b/platform-includes/logs/options/dotnet.mdx index 96e31219896d5..dafa5a8743044 100644 --- a/platform-includes/logs/options/dotnet.mdx +++ b/platform-includes/logs/options/dotnet.mdx @@ -1,9 +1,9 @@ #### Experimental.EnableLogs -Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs, as well as logging integrations via the [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) API. +Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs, as well as logging integrations via the `ILogger` API. -#### Experimental.SetBeforeSendLog(Func) +#### Experimental.SetBeforeSendLog -To filter logs, or update them before they are sent to Sentry, you can use the `Experimental.SetBeforeSendLog()` option. +To filter logs, or update them before they are sent to Sentry, you can use the `Experimental.SetBeforeSendLog(Func)` option. ```csharp options => @@ -33,7 +33,7 @@ options => }); ``` -The callback function set via `Experimental.SetBeforeSendLog()` receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it. +The callback function set via `Experimental.SetBeforeSendLog(Func)` receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it. The log object of type `SentryLog` has the following members: - `Timestamp` Property: (`DateTimeOffset`) The timestamp of the log. diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index a766e3acabdb6..e51ef94e75a67 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -17,7 +17,7 @@ Additionally, we may provide method overloads that are not based on _composite f Additionally, when enabled and initialized, the SDK registers a [ILoggerProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerprovider) -that allows sending logs to Sentry via [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) instances resolved through _.NET dependency injection_. +that allows sending logs to Sentry via [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) instances resolved through _.NET dependency injection_. ```csharp public sealed class MyService(ILogger logger) @@ -33,7 +33,7 @@ public sealed class MyService(ILogger logger) } ``` -The `ILogger`'s _CategoryName_, as well as the `EventId` (if provided), are attached as attributes to the logs. +The `ILogger`'s _CategoryName_, as well as the `EventId` (if provided), are attached as attributes to the logs. For more information, see article on [Logging in C# and .NET](https://learn.microsoft.com//dotnet/core/extensions/logging). Sentry Structured Logs also work with [High-performance logging in .NET](https://learn.microsoft.com/dotnet/core/extensions/high-performance-logging) and [Compile-time logging source generation](https://learn.microsoft.com/dotnet/core/extensions/logger-message-generator) alike. From ab395c8a366a9a6c711aa731221669349a737e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Tue, 12 Aug 2025 11:16:33 +0200 Subject: [PATCH 4/7] docs(dotnet/logs): add platforms to getting started --- .../explore/logs/getting-started/index.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index 71e39b43bf7bd..36e31497155b3 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -253,6 +253,21 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s label=".NET" url="/platforms/dotnet/logs/" /> +- +- +- ## Upcoming SDKs From 9cdc9782d1dabb1b693a661e04e5a0f2ff156ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Tue, 12 Aug 2025 12:07:59 +0200 Subject: [PATCH 5/7] docs(dotnet/logs): fix bad PlatformSection syntax --- platform-includes/logs/integrations/dotnet.mdx | 2 +- platform-includes/logs/options/dotnet.mdx | 3 ++- platform-includes/logs/setup/dotnet.mdx | 10 ++++++---- platform-includes/logs/usage/dotnet.mdx | 12 +++++------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/platform-includes/logs/integrations/dotnet.mdx b/platform-includes/logs/integrations/dotnet.mdx index 0ea3b108460e4..e39212ae4540c 100644 --- a/platform-includes/logs/integrations/dotnet.mdx +++ b/platform-includes/logs/integrations/dotnet.mdx @@ -1,6 +1,6 @@ Available integrations: -- [Microsoft.Extensions.Logging](/platforms/dotnet/guides/extensions-logging/logs/) - [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/) 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 dafa5a8743044..54dc0fb21f41c 100644 --- a/platform-includes/logs/options/dotnet.mdx +++ b/platform-includes/logs/options/dotnet.mdx @@ -1,4 +1,5 @@ #### Experimental.EnableLogs + Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs, as well as logging integrations via the `ILogger` API. #### Experimental.SetBeforeSendLog @@ -44,4 +45,4 @@ The log object of type `SentryLog` has the following members: - `Parameters` Property: (`ImmutableArray>`) The parameters to the template string. - `ParentSpanId` Property: (`SpanId?`) The span id of the span that was active when the log was collected. - `TryGetAttribute(string key, out object value)` Method: Gets the attribute value associated with the specified key. Returns `true` if the log contains an attribute with the specified key and it's value is not `null`, otherwise `false`. -- `SetAttribute(string key, object value)` Method: Set a key-value pair of data attached to the log. Supported types are `string`, `bool`, integers up to a size of 64-bit signed, and floating-point numbers up to a size of 64-bit. +- `SetAttribute(string key, object value)` Method: Sets a key-value pair of data attached to the log. Supported types are `string`, `bool`, integers up to a size of 64-bit signed, and floating-point numbers up to a size of 64-bit. diff --git a/platform-includes/logs/setup/dotnet.mdx b/platform-includes/logs/setup/dotnet.mdx index f4e152eef9608..9ebb12aaaa741 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 => @@ -13,7 +13,7 @@ SentrySdk.Init(options => - + ```csharp {tabTitle:Builder} .UseSentry(options => @@ -39,15 +39,17 @@ SentrySdk.Init(options => - + ```json {tabTitle:Configuration} {filename:appsettings.json} +{ "Sentry": { "Dsn": "___PUBLIC_DSN___", "Experimental": { "EnableLogs": true } - }, + } +} ``` diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index e51ef94e75a67..9d769b7642a10 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -14,7 +14,7 @@ During the experimental phase of the feature, we will provide more method overlo Additionally, we may provide method overloads that are not based on _composite format strings_, but on _interpolated strings_. - + Additionally, when enabled and initialized, the SDK registers a [ILoggerProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerprovider) that allows sending logs to Sentry via [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) instances resolved through _.NET dependency injection_. @@ -22,20 +22,18 @@ that allows sending logs to Sentry via [ILogger](https://learn.microsoft.com/dot ```csharp public sealed class MyService(ILogger logger) { - public async Task InvokeAsync(HttpContext context) + public void Invoke() { logger.LogInformation("A simple log message"); - await Task.Yield(); logger.LogError("A {Parameter} log message", "formatted"); - await Task.Delay(TimeSpan.FromSeconds(1)); - logger.LogWarning(new EventId(1, nameof(InvokeAsync)), "Message with EventId"); + logger.LogWarning(new EventId(1, nameof(Invoke)), "Message with EventId"); } } ``` The `ILogger`'s _CategoryName_, as well as the `EventId` (if provided), are attached as attributes to the logs. -For more information, see article on [Logging in C# and .NET](https://learn.microsoft.com//dotnet/core/extensions/logging). +For more information, see the article on [Logging in C# and .NET](https://learn.microsoft.com//dotnet/core/extensions/logging). Sentry Structured Logs also work with [High-performance logging in .NET](https://learn.microsoft.com/dotnet/core/extensions/high-performance-logging) and [Compile-time logging source generation](https://learn.microsoft.com/dotnet/core/extensions/logger-message-generator) alike. @@ -60,4 +58,4 @@ Supported attribute types are: - Integral: `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `long` and `nint` - Floating-point: `float` and `double` -Unsupported numeric types such as `ulong`, `nuint`, `decimal`, as well as all other types including `object`, are treated as `string` via `ToString`. +Unsupported numeric types such as `ulong`, `nuint`, `decimal`, as well as all other types including `object`, are treated as `string` via `ToString()`. From 188f096e39fccbed3a5fda93b769b8741fdcd4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Wed, 13 Aug 2025 14:56:52 +0200 Subject: [PATCH 6/7] docs(dotnet/logs): fix hyphenation Co-authored-by: Alex Krawiec --- docs/platforms/dotnet/common/logs/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx index 86dd29732c6cf..ed67f09446c9e 100644 --- a/docs/platforms/dotnet/common/logs/index.mdx +++ b/docs/platforms/dotnet/common/logs/index.mdx @@ -13,7 +13,7 @@ notSupported: -With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes. +With Sentry Structured Logs, you can send text-based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes. ## Requirements From e918bab078b38080dc6f0a8495677a777d9d0291 Mon Sep 17 00:00:00 2001 From: Flash0ver <38893694+Flash0ver@users.noreply.github.com> Date: Wed, 13 Aug 2025 16:33:36 +0200 Subject: [PATCH 7/7] docs(dotnet/logs): highlight ILogger integration --- .../guides/extensions-logging/index.mdx | 5 +++- platform-includes/logs/usage/dotnet.mdx | 25 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/platforms/dotnet/guides/extensions-logging/index.mdx b/docs/platforms/dotnet/guides/extensions-logging/index.mdx index 9ee9df6d4f820..8ca30d77f9798 100644 --- a/docs/platforms/dotnet/guides/extensions-logging/index.mdx +++ b/docs/platforms/dotnet/guides/extensions-logging/index.mdx @@ -9,7 +9,8 @@ Sentry has an integration with `Microsoft.Extensions.Logging` through the [Sentr ## 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: diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index 9d769b7642a10..a0c8515390693 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -1,3 +1,5 @@ + + Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Experimental.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`. @@ -14,10 +16,25 @@ During the experimental phase of the feature, we will provide more method overlo Additionally, we may provide method overloads that are not based on _composite format strings_, but on _interpolated strings_. + + -Additionally, when enabled and initialized, the SDK registers a [ILoggerProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerprovider) -that allows sending logs to Sentry via [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) instances resolved through _.NET dependency injection_. +Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using instances of the [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) interface, +resolved through _.NET dependency injection_. + +The `LoggerExtensions` extension methods expose various overloads that you can use to log messages at six different log levels automatically mapped to Sentry's severity: + +| 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 | + +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 public sealed class MyService(ILogger logger) @@ -38,6 +55,8 @@ Sentry Structured Logs also work with [High-performance logging in .NET](https:/ + + The SDK automatically provides a set of default attributes attached to your logs. Additionally, you can attach custom attributes via a delegate. @@ -59,3 +78,5 @@ Supported attribute types are: - Floating-point: `float` and `double` Unsupported numeric types such as `ulong`, `nuint`, `decimal`, as well as all other types including `object`, are treated as `string` via `ToString()`. + +