-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
docs/core/compatibility/extensions/10.0/console-json-logging-duplicate-messages.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 01/15/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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.