Skip to content

Commit d29c1c5

Browse files
hach-queadamsitnik
andauthored
Make DoesConsoleSupportAnsi respect DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION (#88241)
Co-authored-by: Adam Sitnik <[email protected]>
1 parent 2bb3d07 commit d29c1c5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
6868
[UnsupportedOSPlatformGuard("windows")]
6969
private static bool DoesConsoleSupportAnsi()
7070
{
71+
string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION");
72+
if (envVar is not null && (envVar == "1" || envVar.Equals("true", StringComparison.OrdinalIgnoreCase)))
73+
{
74+
// ANSI color support forcibly enabled via environment variable. This logic matches the behaviour
75+
// found in System.ConsoleUtils.EmitAnsiColorCodes.
76+
return true;
77+
}
7178
if (
7279
#if NETFRAMEWORK
7380
Environment.OSVersion.Platform != PlatformID.Win32NT

0 commit comments

Comments
 (0)