0

I'm trying to output to console by configuring the sink as follows:

{
  "Name": "Console",
  "Args": {
    "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
    "Formatter": {
      "Type": "Serilog.Templates.ExpressionTemplate, Serilog.Expressions",
      "Template": "{@t:yyyy-MM-dd HH:mm:ss.fff} [{@l:u3}] [{#if SourceContext is not null}{Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1)}{#end}{#if MemberName is not null}.{MemberName}{#end}] {@m:lj}\n{@x}"
    }
  }
}

But it's not working. Does this sink not support expression templates?

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • https://github.com/serilog/serilog-expressions shows how to do it without the config wiring - I'd validate my expressions in a testbed and then solve how to wire an ExpressionTemplate after that (have not used expressions or config, but they are orthogonal, and I dont want to see you blocked) – Ruben Bartelink Apr 13 '23 at 16:26
  • @RubenBartelink If I do it in code like `WriteTo.Console(new ExpressionTemplate(...))` with the template above it works fine. But I want to configure the console sink in appsettings. – Ivan-Mark Debono Apr 14 '23 at 04:25
  • OK then the answer to your question "Does the Console Sink support expressions" is YES. The simplified question is "How to wire Serilog Settings parsing to a Console log with an ExpressionTemplate", and you can show the code that works, and the settings layout you are trying. Hopefully someone that understands how the settings binding works can step in – Ruben Bartelink Apr 14 '23 at 13:58

0 Answers0