From 601404ebf260c2bb75921c4dcb2e3d5fe5a8da27 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 Aug 2025 23:36:37 +0000 Subject: [PATCH 1/5] Initial plan From aad9b71bf41b922c3f2c504736f569a65931a336 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 Aug 2025 23:45:06 +0000 Subject: [PATCH 2/5] Add breaking change documentation for Console JSON logging duplicate messages Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com> --- docs/core/compatibility/10.0.md | 1 + ...console-json-logging-duplicate-messages.md | 84 +++++++++++++++++++ docs/core/compatibility/toc.yml | 2 + 3 files changed, 87 insertions(+) create mode 100644 docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md index 1b71ea787cc16..430418e9796c8 100644 --- a/docs/core/compatibility/10.0.md +++ b/docs/core/compatibility/10.0.md @@ -41,6 +41,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af | Title | Type of change | Introduced version | |-------|---------------------|--------------------| +| [Avoid duplicate messages in Console logging with Json formatter](extensions/10.0/console-json-logging-duplicate-messages.md) | Behavioral change | Preview 7 | | [ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly](extensions/10.0/provideraliasattribute-moved-assembly.md) | Source incompatible | Preview 4 | | [Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code](extensions/10.0/dynamically-accessed-members-configuration.md) | Binary incompatible | Preview 6 | diff --git a/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md new file mode 100644 index 0000000000000..b1055272866df --- /dev/null +++ b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md @@ -0,0 +1,84 @@ +--- +title: "Breaking change: Avoid duplicate messages in Console logging with Json formatter" +description: "Learn about the breaking change in .NET 10 where duplicate messages are avoided in Console logging with JSON formatter." +ms.date: 01/15/2025 +ai-usage: ai-assisted +ms.custom: https://github.com/dotnet/docs/issues/47006 +--- + +# Avoid duplicate messages in Console logging with Json formatter + +When logging to the console using the JSON formatter, log messages are no longer duplicated in the log output. Previously, messages typically appeared three times: once as the top-level `Message`, again within the `State` object, and a third time as the original format string. + +## Version introduced + +.NET 10 Preview 7 + +## Previous behavior + +Previously, when using a console logger configured with the JSON formatter, log messages were duplicated in the output. For example: + +```csharp +logger.LogInformation("This is an information message."); +``` + +This code would produce output like: + +```json +{ + "EventId": 0, + "LogLevel": "Information", + "Category": "Program", + "Message": "This is an information message.", + "State": { + "Message": "This is an information message.", + "{OriginalFormat}": "This is an information message." + } +} +``` + +As you can see, `Message` appears twice—once as the top-level `Message` and again inside the `State` object. + +## New behavior + +After the change, the log output looks like this: + +```json +{ + "EventId": 0, + "LogLevel": "Information", + "Category": "Program", + "Message": "This is an information message.", + "State": { + "{OriginalFormat}": "This is an information message." + } +} +``` + +The `Message` is no longer duplicated—it now appears only at the top level, resulting in cleaner and more concise log output. + +## Type of breaking change + +This is a [behavioral change](../../categories.md#behavioral-change). + +## Reason for change + +The goal of this change is to reduce unnecessary logging overhead by eliminating duplicate content. By avoiding repeated formatting of the same message, the change helps: + +- **Minimize log output size** +- **Reduce confusion caused by redundant information** +- **Improve performance by preventing multiple formatting operations for the same message** + +Overall, this results in cleaner, more efficient, and easier-to-read logs. + +## Recommended action + +For users who were previously parsing the logging output and extracting the `Message` from within the `State` object, it's safe to use the top-level `Message` instead, now that duplication has been removed. + +> [!NOTE] +> In some cases, a `Message` might still appear within the `State` object—this typically happens when its content differs from the top-level `Message`. + +## Affected APIs + +- +- [Microsoft.Extensions.Logging.Console NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console) diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index bef069b8a508c..0f39fe17635e0 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -50,6 +50,8 @@ items: href: cryptography/10.0/x509-publickey-null.md - name: Extensions items: + - name: "Avoid duplicate messages in Console logging with Json formatter" + href: extensions/10.0/console-json-logging-duplicate-messages.md - name: "ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly" href: extensions/10.0/provideraliasattribute-moved-assembly.md - name: "Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code" From 3101e2e1c1a4686c6173110fbeedb01e7b040b34 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 7 Aug 2025 11:43:14 -0700 Subject: [PATCH 3/5] human edits --- docs/core/compatibility/10.0.md | 2 +- ...console-json-logging-duplicate-messages.md | 33 +++++++++---------- docs/core/compatibility/toc.yml | 2 +- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md index 430418e9796c8..81a4062ff8a12 100644 --- a/docs/core/compatibility/10.0.md +++ b/docs/core/compatibility/10.0.md @@ -41,7 +41,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af | Title | Type of change | Introduced version | |-------|---------------------|--------------------| -| [Avoid duplicate messages in Console logging with Json formatter](extensions/10.0/console-json-logging-duplicate-messages.md) | Behavioral change | Preview 7 | +| [Avoid duplicate messages in Console logging with JSON formatter](extensions/10.0/console-json-logging-duplicate-messages.md) | Behavioral change | Preview 7 | | [ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly](extensions/10.0/provideraliasattribute-moved-assembly.md) | Source incompatible | Preview 4 | | [Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code](extensions/10.0/dynamically-accessed-members-configuration.md) | Binary incompatible | Preview 6 | diff --git a/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md index b1055272866df..0518cade7ffce 100644 --- a/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md +++ b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md @@ -1,12 +1,12 @@ --- -title: "Breaking change: Avoid duplicate messages in Console logging with Json formatter" +title: "Breaking change: Avoid duplicate messages in Console logging with JSON formatter" description: "Learn about the breaking change in .NET 10 where duplicate messages are avoided in Console logging with JSON formatter." ms.date: 01/15/2025 ai-usage: ai-assisted ms.custom: https://github.com/dotnet/docs/issues/47006 --- -# Avoid duplicate messages in Console logging with Json formatter +# Avoid duplicate messages in Console logging with JSON formatter When logging to the console using the JSON formatter, log messages are no longer duplicated in the log output. Previously, messages typically appeared three times: once as the top-level `Message`, again within the `State` object, and a third time as the original format string. @@ -16,13 +16,7 @@ When logging to the console using the JSON formatter, log messages are no longer ## Previous behavior -Previously, when using a console logger configured with the JSON formatter, log messages were duplicated in the output. For example: - -```csharp -logger.LogInformation("This is an information message."); -``` - -This code would produce output like: +Previously, when using a console logger configured with the JSON formatter, log messages were duplicated in the output. For example, the code `logger.LogInformation("This is an information message.");` produced the following output: ```json { @@ -37,11 +31,11 @@ This code would produce output like: } ``` -As you can see, `Message` appears twice—once as the top-level `Message` and again inside the `State` object. +As you can see, `Message` appears twice: once as the top-level `Message` and again inside the `State` object. ## New behavior -After the change, the log output looks like this: +Starting in .NET 10, the log output looks like this: ```json { @@ -55,7 +49,7 @@ After the change, the log output looks like this: } ``` -The `Message` is no longer duplicated—it now appears only at the top level, resulting in cleaner and more concise log output. +`Message` is no longer duplicated. It now appears only at the top level, resulting in cleaner and more concise log output. ## Type of breaking change @@ -65,20 +59,23 @@ This is a [behavioral change](../../categories.md#behavioral-change). The goal of this change is to reduce unnecessary logging overhead by eliminating duplicate content. By avoiding repeated formatting of the same message, the change helps: -- **Minimize log output size** -- **Reduce confusion caused by redundant information** -- **Improve performance by preventing multiple formatting operations for the same message** +- Minimize log output size. +- Reduce confusion caused by redundant information. +- Improve performance by preventing multiple formatting operations for the same message. Overall, this results in cleaner, more efficient, and easier-to-read logs. ## Recommended action -For users who were previously parsing the logging output and extracting the `Message` from within the `State` object, it's safe to use the top-level `Message` instead, now that duplication has been removed. +If you previously parsed the logging output to extract the `Message` from within the `State` object, it's safe to use the top-level `Message` instead, now that duplication has been removed. > [!NOTE] -> In some cases, a `Message` might still appear within the `State` object—this typically happens when its content differs from the top-level `Message`. +> In some cases, a `Message` might still appear within the `State` object. This typically happens when its content differs from the top-level `Message`. ## Affected APIs - -- [Microsoft.Extensions.Logging.Console NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console) +- +- +- +- diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index 0f39fe17635e0..e9d9b9c24c59d 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -50,7 +50,7 @@ items: href: cryptography/10.0/x509-publickey-null.md - name: Extensions items: - - name: "Avoid duplicate messages in Console logging with Json formatter" + - name: "Avoid duplicate messages in Console logging with JSON formatter" href: extensions/10.0/console-json-logging-duplicate-messages.md - name: "ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly" href: extensions/10.0/provideraliasattribute-moved-assembly.md From 4aa5e564dcc1513d0fd1846dc0d23ffa2f22bfac Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 7 Aug 2025 11:55:30 -0700 Subject: [PATCH 4/5] change title --- docs/core/compatibility/10.0.md | 2 +- .../10.0/console-json-logging-duplicate-messages.md | 10 ++++------ docs/core/compatibility/toc.yml | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md index 81a4062ff8a12..304f370527f5a 100644 --- a/docs/core/compatibility/10.0.md +++ b/docs/core/compatibility/10.0.md @@ -41,7 +41,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af | Title | Type of change | Introduced version | |-------|---------------------|--------------------| -| [Avoid duplicate messages in Console logging with JSON formatter](extensions/10.0/console-json-logging-duplicate-messages.md) | Behavioral change | Preview 7 | +| [Message no longer duplicated in Console log output](extensions/10.0/console-json-logging-duplicate-messages.md) | Behavioral change | Preview 7 | | [ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly](extensions/10.0/provideraliasattribute-moved-assembly.md) | Source incompatible | Preview 4 | | [Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code](extensions/10.0/dynamically-accessed-members-configuration.md) | Binary incompatible | Preview 6 | diff --git a/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md index 0518cade7ffce..f3b2773ce8a93 100644 --- a/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md +++ b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md @@ -1,12 +1,12 @@ --- -title: "Breaking change: Avoid duplicate messages in Console logging with JSON formatter" -description: "Learn about the breaking change in .NET 10 where duplicate messages are avoided in Console logging with JSON formatter." +title: "Breaking change: Message no longer duplicated in Console log output" +description: "Learn about the breaking change in .NET 10 where `Message` is no longer duplicated in Console log output using the JSON formatter." ms.date: 01/15/2025 ai-usage: ai-assisted ms.custom: https://github.com/dotnet/docs/issues/47006 --- -# Avoid duplicate messages in Console logging with JSON formatter +# Message no longer duplicated in Console log output When logging to the console using the JSON formatter, log messages are no longer duplicated in the log output. Previously, messages typically appeared three times: once as the top-level `Message`, again within the `State` object, and a third time as the original format string. @@ -35,7 +35,7 @@ As you can see, `Message` appears twice: once as the top-level `Message` and aga ## New behavior -Starting in .NET 10, the log output looks like this: +Starting in .NET 10, `Message` appears only at the top level and not inside the `State` object (typically). The log output looks like this: ```json { @@ -49,8 +49,6 @@ Starting in .NET 10, the log output looks like this: } ``` -`Message` is no longer duplicated. It now appears only at the top level, resulting in cleaner and more concise log output. - ## Type of breaking change This is a [behavioral change](../../categories.md#behavioral-change). diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index e9d9b9c24c59d..e34dc4c2a4639 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -50,11 +50,11 @@ items: href: cryptography/10.0/x509-publickey-null.md - name: Extensions items: - - name: "Avoid duplicate messages in Console logging with JSON formatter" + - name: Message no longer duplicated in Console log output href: extensions/10.0/console-json-logging-duplicate-messages.md - - name: "ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly" + - name: ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly href: extensions/10.0/provideraliasattribute-moved-assembly.md - - name: "Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code" + - name: Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code href: extensions/10.0/dynamically-accessed-members-configuration.md - name: Globalization items: From 47b8bdb4139fb7fa9d8f5d9e2732e780937af0f4 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:14:55 -0700 Subject: [PATCH 5/5] Update date --- .../extensions/10.0/console-json-logging-duplicate-messages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md index f3b2773ce8a93..ae33060e537b6 100644 --- a/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md +++ b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md @@ -1,7 +1,7 @@ --- title: "Breaking change: Message no longer duplicated in Console log output" description: "Learn about the breaking change in .NET 10 where `Message` is no longer duplicated in Console log output using the JSON formatter." -ms.date: 01/15/2025 +ms.date: 08/07/2025 ai-usage: ai-assisted ms.custom: https://github.com/dotnet/docs/issues/47006 ---