Skip to content

Commit

Permalink
Support NO_COLOR environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r committed Mar 16, 2024
1 parent 1f0919e commit cf2c80d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static LoggerConfiguration Console(
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ public static LoggerConfiguration Console(
IFormatProvider? formatProvider = null,
LoggingLevelSwitch? levelSwitch = null,
LogEventLevel? standardErrorFromLevel = null,
ConsoleTheme? theme = null,
ConsoleTheme? theme = null,
bool applyThemeToRedirectedOutput = false,
object? syncRoot = null)
{
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));

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

Expand Down

0 comments on commit cf2c80d

Please sign in to comment.