serilog / serilog-sinks-console

Write log events to System.Console as text or JSON, with ANSI theme support
Apache License 2.0
248 stars 72 forks source link

Support NO_COLOR environment variable #154

Closed sungam3r closed 8 months ago

sungam3r commented 8 months ago

fixes #153

nblumhardt commented 8 months ago

Awesome :+1:

borland commented 8 months ago

Thanks!

rcdailey commented 5 months ago

I tested this out but it doesn't work for me. Will this not work in combination with Serilog.Expressions?

EDIT: I ended up having to implement this manually, like so:

private ExpressionTemplate GetConsoleTemplate()
{
    var template = "[{@l:u3}] " + GetBaseTemplateString() +
        "{#if SanitizedExceptionMessage is not null}: {SanitizedExceptionMessage}{#end}\n";

    var raw = !string.IsNullOrEmpty(env.GetEnvironmentVariable("NO_COLOR"));
    return new ExpressionTemplate(template, theme: raw ? null : TemplateTheme.Code);
}

Again, I'm not sure if this is an issue specific to Serilog.Expressions, but this solution works for me.

nblumhardt commented 5 months ago

👍 Serilog.Expressions has its own theming implementation