question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Is it possible to use an ExpressionTemplate using config (appsettings.json)?

See original GitHub issue

I’d like to write something like this in my appsettings.json:

{
  "Serilog": {
    "Using": [
      "Serilog.Expressions"
    ],
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "outputTemplate": "[{@t:HH:mm:ss} {@l:u3} ({SourceContext})] {@m} (first item is {Items[0]})\n{@x}"
        }
      }
    ]
  }
}

Obviously the outputTemplate doesn’t support expressions. Is there any way to accomplish this? Perhaps this question is better suited to the https://github.com/serilog/serilog-settings-configuration repo.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
thargycommented, Oct 13, 2021

For anyone else finding this issue, this is actually possible and documented in serilog-settings-configuration, e.g.:

{
  "Name": "Console",
  "Args": {
    "formatter": {
      // `type` (or $type) is optional, must be specified for abstract declared parameter types
      "type": "Serilog.Templates.ExpressionTemplate, Serilog.Expressions",
      "template": "[{@t:HH:mm:ss} {@l:u3} {Coalesce(SourceContext, '<none>')}] {@m}\n{@x}"
  }
}
4reactions
skomis-mmcommented, Oct 14, 2022

Hi @sanghel-payoff , @rdewaele this is the correct config:

"WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": {
            "type": "Serilog.Templates.ExpressionTemplate, Serilog.Expressions",
            "template": "{@t:HH:mm:ss} {@l:u3}\n",
            "theme": "Serilog.Templates.Themes.TemplateTheme::Code, Serilog.Expressions"
          }
        }
      }
    ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Expression Template with appSettings in Serilog
I've a file sink configured in the appsettings. json of my application. It works perfectly but now I want to add an expression...
Read more >
Customized JSON formatting with Serilog
This post collects all kinds of JSON formatting examples using ExpressionTemplate , and I'll add to them as new questions come my way...
Read more >
Intro to AppSettings in .NET Core - YouTube
In fact, by default, we get five different places to put our settings in each .NET Core application. In this video, we will...
Read more >
Appsettings.json in .NET: How to read and get a value
The appsettings. json is used in .NET and .NET Core applications to read and get a value from the configuration file using the...
Read more >
Is there a way to set Serilog formatter variables via appsettings ...
Coding example for the question Is there a way to set Serilog formatter variables via appsettings.json?-.net-core.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found