From 01563d1dd0d6877c5c48b8e029b3ee85f5033dcc Mon Sep 17 00:00:00 2001 From: Petr Onderka Date: Wed, 26 Aug 2026 14:15:49 +0200 Subject: [PATCH 1/3] Document generic logging methods in .NET 11 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/core/whats-new/dotnet-11/libraries.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/core/whats-new/dotnet-11/libraries.md b/docs/core/whats-new/dotnet-11/libraries.md index 0c84cb9e77957..db4e3ec7ca1ce 100644 --- a/docs/core/whats-new/dotnet-11/libraries.md +++ b/docs/core/whats-new/dotnet-11/libraries.md @@ -2,7 +2,7 @@ title: What's new in .NET libraries for .NET 11 description: Learn about the updates to the .NET libraries for .NET 11. titleSuffix: "" -ms.date: 08/12/2026 +ms.date: 08/25/2026 ai-usage: ai-assisted ms.update-cycle: 3650-days --- @@ -518,7 +518,7 @@ The class now inclu These constants can be used with the `StringSyntax` attribute to provide better tooling support for string literals containing code in these languages. -## Caching and configuration +## Caching, configuration, and logging - [Configuration binding](#configuration-binding) - [MemoryCache OpenTelemetry metrics](#memorycache-opentelemetry-metrics) @@ -527,6 +527,7 @@ These constants can be used with the `StringSyntax` attribute to provide better - [Options-aware HybridCache factories](#options-aware-hybridcache-factories) - [Asynchronous validation with DataAnnotations](#asynchronous-validation-with-dataannotations) - [Activity tracing configuration](#activity-tracing-configuration) +- [Generic source-generated logging methods](#generic-source-generated-logging-methods) ### Configuration binding @@ -641,6 +642,16 @@ builder.Services.AddTracing(tracing => The same release adds `ActivitySourceFactory` and unseals `ActivitySource`, which together support factory-driven creation and refreshable listeners. +### Generic source-generated logging methods + +The logging source generator now supports generic methods decorated with , primarily to avoid boxing. Generic type parameters can use standard constraints, such as `class`, `struct`, `unmanaged`, interfaces, base types, and `new()`. The `allows ref struct` anti-constraint isn't supported and produces [SYSLIB1011](../../../fundamentals/syslib-diagnostics/syslib1011.md). + +```csharp +[LoggerMessage(0, LogLevel.Trace, "Received {Code} ({Length} bytes)")] +public static partial void PacketReceived(ILogger logger, TCode code, int length) + where TCode : struct, Enum; +``` + ## Cryptography - [X25519 Diffie-Hellman key exchange](#x25519-diffie-hellman-key-exchange) From cbf5d2b4460d9e54cceccb990765cdb1c6c97a7c Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:15:14 -0700 Subject: [PATCH 2/3] Apply suggestion from @gewarren --- docs/core/whats-new/dotnet-11/libraries.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/core/whats-new/dotnet-11/libraries.md b/docs/core/whats-new/dotnet-11/libraries.md index 261b12eec3c6d..8c0b338eb191d 100644 --- a/docs/core/whats-new/dotnet-11/libraries.md +++ b/docs/core/whats-new/dotnet-11/libraries.md @@ -651,7 +651,6 @@ The logging source generator now supports generic methods decorated with (ILogger logger, TCode code, int length) where TCode : struct, Enum; -``` ### Improved reliability for configuration file change detection The type, which configuration providers use to detect configuration file changes, includes several reliability improvements. From 89001a1155cb601463b56f1d4b5a313f867444e2 Mon Sep 17 00:00:00 2001 From: Petr Onderka Date: Fri, 28 Aug 2026 13:35:38 +0200 Subject: [PATCH 3/3] Add backticks back --- docs/core/whats-new/dotnet-11/libraries.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/core/whats-new/dotnet-11/libraries.md b/docs/core/whats-new/dotnet-11/libraries.md index 8c0b338eb191d..a681e2fff6873 100644 --- a/docs/core/whats-new/dotnet-11/libraries.md +++ b/docs/core/whats-new/dotnet-11/libraries.md @@ -651,6 +651,8 @@ The logging source generator now supports generic methods decorated with (ILogger logger, TCode code, int length) where TCode : struct, Enum; +``` + ### Improved reliability for configuration file change detection The type, which configuration providers use to detect configuration file changes, includes several reliability improvements.