Skip to content

Commit 1c35ad9

Browse files
authored
Merge pull request #154 from sungam3r/nocolor
Support NO_COLOR environment variable
2 parents 1f0919e + cf2c80d commit 1c35ad9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Serilog.Sinks.Console/ConsoleAuditLoggerConfigurationExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public static LoggerConfiguration Console(
6363
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
6464
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));
6565

66-
var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ?
66+
// see https://no-color.org/
67+
var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NO_COLOR")) ?
6768
ConsoleTheme.None :
6869
theme ?? SystemConsoleThemes.Literate;
6970

src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ public static LoggerConfiguration Console(
5959
IFormatProvider? formatProvider = null,
6060
LoggingLevelSwitch? levelSwitch = null,
6161
LogEventLevel? standardErrorFromLevel = null,
62-
ConsoleTheme? theme = null,
62+
ConsoleTheme? theme = null,
6363
bool applyThemeToRedirectedOutput = false,
6464
object? syncRoot = null)
6565
{
6666
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
6767
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));
6868

69-
var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ?
69+
// see https://no-color.org/
70+
var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NO_COLOR")) ?
7071
ConsoleTheme.None :
7172
theme ?? SystemConsoleThemes.Literate;
7273

0 commit comments

Comments
 (0)