Skip to content

Commit 7e35b03

Browse files
authored
Add breaking change documentation for Console JSON logging duplicate messages (#47741)
1 parent c7b9a64 commit 7e35b03

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
4141

4242
| Title | Type of change | Introduced version |
4343
|-------|---------------------|--------------------|
44+
| [Message no longer duplicated in Console log output](extensions/10.0/console-json-logging-duplicate-messages.md) | Behavioral change | Preview 7 |
4445
| [ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly](extensions/10.0/provideraliasattribute-moved-assembly.md) | Source incompatible | Preview 4 |
4546
| [Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code](extensions/10.0/dynamically-accessed-members-configuration.md) | Binary incompatible | Preview 6 |
4647

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: "Breaking change: Message no longer duplicated in Console log output"
3+
description: "Learn about the breaking change in .NET 10 where `Message` is no longer duplicated in Console log output using the JSON formatter."
4+
ms.date: 08/07/2025
5+
ai-usage: ai-assisted
6+
ms.custom: https://github.com/dotnet/docs/issues/47006
7+
---
8+
9+
# Message no longer duplicated in Console log output
10+
11+
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.
12+
13+
## Version introduced
14+
15+
.NET 10 Preview 7
16+
17+
## Previous behavior
18+
19+
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:
20+
21+
```json
22+
{
23+
"EventId": 0,
24+
"LogLevel": "Information",
25+
"Category": "Program",
26+
"Message": "This is an information message.",
27+
"State": {
28+
"Message": "This is an information message.",
29+
"{OriginalFormat}": "This is an information message."
30+
}
31+
}
32+
```
33+
34+
As you can see, `Message` appears twice: once as the top-level `Message` and again inside the `State` object.
35+
36+
## New behavior
37+
38+
Starting in .NET 10, `Message` appears only at the top level and not inside the `State` object (typically). The log output looks like this:
39+
40+
```json
41+
{
42+
"EventId": 0,
43+
"LogLevel": "Information",
44+
"Category": "Program",
45+
"Message": "This is an information message.",
46+
"State": {
47+
"{OriginalFormat}": "This is an information message."
48+
}
49+
}
50+
```
51+
52+
## Type of breaking change
53+
54+
This is a [behavioral change](../../categories.md#behavioral-change).
55+
56+
## Reason for change
57+
58+
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:
59+
60+
- Minimize log output size.
61+
- Reduce confusion caused by redundant information.
62+
- Improve performance by preventing multiple formatting operations for the same message.
63+
64+
Overall, this results in cleaner, more efficient, and easier-to-read logs.
65+
66+
## Recommended action
67+
68+
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.
69+
70+
> [!NOTE]
71+
> In some cases, a `Message` might still appear within the `State` object. This typically happens when its content differs from the top-level `Message`.
72+
73+
## Affected APIs
74+
75+
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole%2A?displayProperty=fullName>
76+
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsoleFormatter*?displayProperty=fullName>
77+
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddJsonConsole*?displayProperty=fullName>
78+
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddSimpleConsole*?displayProperty=fullName>
79+
- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddSystemdConsole*?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ items:
5050
href: cryptography/10.0/x509-publickey-null.md
5151
- name: Extensions
5252
items:
53-
- name: "ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly"
53+
- name: Message no longer duplicated in Console log output
54+
href: extensions/10.0/console-json-logging-duplicate-messages.md
55+
- name: ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly
5456
href: extensions/10.0/provideraliasattribute-moved-assembly.md
55-
- name: "Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code"
57+
- name: Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code
5658
href: extensions/10.0/dynamically-accessed-members-configuration.md
5759
- name: Globalization
5860
items:

0 commit comments

Comments
 (0)