diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md index 1b71ea787cc16..304f370527f5a 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 | |-------|---------------------|--------------------| +| [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 new file mode 100644 index 0000000000000..ae33060e537b6 --- /dev/null +++ b/docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md @@ -0,0 +1,79 @@ +--- +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: 08/07/2025 +ai-usage: ai-assisted +ms.custom: https://github.com/dotnet/docs/issues/47006 +--- + +# 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. + +## 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, the code `logger.LogInformation("This is an information message.");` produced the following output: + +```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 + +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 +{ + "EventId": 0, + "LogLevel": "Information", + "Category": "Program", + "Message": "This is an information message.", + "State": { + "{OriginalFormat}": "This is an information message." + } +} +``` + +## 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 + +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`. + +## Affected APIs + +- +- +- +- +- diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index bef069b8a508c..e34dc4c2a4639 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -50,9 +50,11 @@ items: href: cryptography/10.0/x509-publickey-null.md - name: Extensions items: - - name: "ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly" + - 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 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: