Skip to content

Commit aad9b71

Browse files
Copilotgewarren
andcommitted
Add breaking change documentation for Console JSON logging duplicate messages
Co-authored-by: gewarren <[email protected]>
1 parent 601404e commit aad9b71

File tree

3 files changed

+87
-0
lines changed

3 files changed

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

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ items:
5050
href: cryptography/10.0/x509-publickey-null.md
5151
- name: Extensions
5252
items:
53+
- name: "Avoid duplicate messages in Console logging with Json formatter"
54+
href: extensions/10.0/console-json-logging-duplicate-messages.md
5355
- name: "ProviderAliasAttribute moved to Microsoft.Extensions.Logging.Abstractions assembly"
5456
href: extensions/10.0/provideraliasattribute-moved-assembly.md
5557
- name: "Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code"

0 commit comments

Comments
 (0)