As of version 3.3.0 of Serilog.Settings.Configuration, this is now possible:
{
"Name": "Console",
"Args": {
"formatter": {
"type": "Serilog.Templates.ExpressionTemplate, Serilog.Expressions",
"template": "[{@t:HH:mm:ss} {@l:u3} {Coalesce(SourceContext, '<none>')}] {@m}\n{@x}"
}
}
}
For earlier versions there's no direct support, but if you put the template into a static property somewhere:
public static class Formatters
{
public static ITextFormatter Output { get; } = new ExpressionTemplate(...);
}
Then you can pass that value through JSON configuration by naming the static property:
{
"Name": "Console",
"Args": { "formatter"" "YourApp.Formatters::Output, YourApp" }
}
(Check the arguments accepted by the sink to see what the name of the formatter argument is - but it should be formatter
as above in most cases.)