Skip to content

Add breaking change documentation for Console JSON logging duplicate messages #47741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
Original file line number Diff line number Diff line change
@@ -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

- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole%2A?displayProperty=fullName>
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsoleFormatter*?displayProperty=fullName>
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddJsonConsole*?displayProperty=fullName>
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddSimpleConsole*?displayProperty=fullName>
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddSystemdConsole*?displayProperty=fullName>
6 changes: 4 additions & 2 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down