|
| 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> |
0 commit comments