Skip to content

[Breaking change]: Simple and Systemd console formatters escape terminal control characters #55741

Closed as not planned

Description

@rosebyte

Description

Starting in .NET 11 Preview 7, the built-in Simple and Systemd console log formatters escape terminal control characters in formatted messages, exception text, logger categories, and scopes before writing them to the console.

Characters in the C0 range (U+0000 through U+001F), DEL (U+007F), and the C1 range (U+0080 through U+009F) are written as \uXXXX, except for tab (U+0009), line feed (U+000A), and carriage return (U+000D), which remain available for log formatting.

The JSON console formatter is unchanged and continues to escape characters through Utf8JsonWriter. Custom console formatters are also unchanged and remain responsible for their own output.

This behaviour was introduced by dotnet/runtime#128741.

Version

.NET 11 Preview 7

Previous behavior

The built-in Simple and Systemd console formatters wrote control characters from formatted messages, exception text, logger categories, and scopes directly to their output. A terminal could interpret these characters rather than display them as text.

For example:

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;

using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
    builder.AddSimpleConsole(options =>
        options.ColorBehavior = LoggerColorBehavior.Disabled));

ILogger logger = loggerFactory.CreateLogger("Example");
logger.LogInformation("Payload: {Value}", "prefix\u001B[31mred\u001B[0m");

The U+001B escape characters were written verbatim, so a compatible terminal could interpret the payload as ANSI instructions and display red using a different colour.

New behavior

The built-in Simple and Systemd console formatters replace terminal control characters with visible, uppercase Unicode escape sequences. With the preceding example, the payload portion of the output is:

Payload: prefix\u001B[31mred\u001B[0m

The terminal receives the six literal characters \u001B for each escape character and therefore does not interpret the logged payload as an ANSI control sequence.

The change applies to values written from:

  • Formatted log messages
  • Exception text
  • Logger categories
  • Logging scopes

Tab, line feed, and carriage return characters retain their existing formatting behaviour. Unicode format characters outside the C0, DEL, and C1 ranges are not changed by the Simple and Systemd formatters. The JSON console formatter continues to use its existing JSON escaping.

Type of breaking change

  • Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
  • Behavioral change: Existing binaries might behave differently at run time.

Reason for change

Untrusted values can contain control characters that manipulate terminal output, obscure or rewrite preceding text, change colours, or interfere with tools that consume standard output. Escaping the terminal-driving C0, DEL, and C1 ranges provides defence in depth when applications log user-controlled data. The selected ranges follow the approach used by OpenSSH and systemd for terminal output.

Recommended action

Most applications require no action.

If tests, parsers, or other tooling compare the exact text produced by the built-in Simple or Systemd formatter, update them to expect \uXXXX escape sequences for affected control characters.

If an application intentionally needs raw control sequences in console output, use a custom ConsoleFormatter that implements the required output policy. There is no option on the built-in Simple or Systemd formatter to restore the previous behaviour. Applications using the JSON formatter or a custom formatter are unaffected by this change.

Feature area

Extensions

Affected APIs

  • All Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddSimpleConsole(...) overloads
  • All Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddSystemdConsole(...) overloads
  • All Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole(...) overloads when the built-in Simple or Systemd formatter is selected
  • Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.FormatterName when it selects the built-in Simple or Systemd formatter

Activity

  1. added
    breaking-change
    on Aug 26, 2026
  2. self-assigned this
    on Aug 26, 2026
  3. rosebyte commented on Aug 26, 2026

    @rosebyte
    MemberAuthor

    Revoked as acceptable change as users aren't supposed to use the filtered characters in logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

breaking-change

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions