Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring Console with theme overrides ExpressionTemplate #350

Open
mpiliszcz opened this issue Feb 14, 2023 · 1 comment
Open

Configuring Console with theme overrides ExpressionTemplate #350

mpiliszcz opened this issue Feb 14, 2023 · 1 comment

Comments

@mpiliszcz
Copy link

mpiliszcz commented Feb 14, 2023

  "Serilog": {
    "Using": [ "Serilog.Sinks.Console" ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Information",
        "System": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": {
            "type": "Serilog.Templates.ExpressionTemplate, Serilog.Expressions",
            "template": "[{@t:HH:mm:ss}{#if CorrelationId is not null} {Substring(CorrelationId, 0,5)}{#end} {@l:u3}] {#if SourceContext is not null}{SourceContext}{#end}{@m}\n{@x}"
          }//,
          //"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Literate, Serilog.Sinks.Console"
        }
      }
    ],
    "Enrich": [ "WithCorrelationId" ]
  },

If I remove commented out theme definition, the formatter will no longer be used, only theme will be finally configured.
We can't have both.

@0xced
Copy link
Member

0xced commented Feb 14, 2023

Indeed you can't have both, but that's how the Serilog.Sinks.Console package works. This is not related to this Serilog.Settings.Configuration package.

If you write it programmatically you can configure either the theme:

configuration.WriteTo.Console(theme: AnsiConsoleTheme.Code);

or the formatter:

configuration.WriteTo.Console(formatter: new ExpressionTemplate("[{@t:HH:mm:ss}{#if CorrelationId is not null} {Substring(CorrelationId, 0,5)}{#end} {@l:u3}] {#if SourceContext is not null}{SourceContext}{#end}{@m}\n{@x}"));

But you can't have both, this does not even compile:

configuration.WriteTo.Console(
    theme: AnsiConsoleTheme.Literate,
    formatter: new ExpressionTemplate("[{@t:HH:mm:ss}{#if CorrelationId is not null} {Substring(CorrelationId, 0,5)}{#end} {@l:u3}] {#if SourceContext is not null}{SourceContext}{#end}{@m}\n{@x}")
);

Does this answer address your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants