A. Wheatman
A. Wheatman

Reputation: 6386

How to set formatProvider property in Serilog from app.config file

I know that it's possible to setup Serilog sinks in app.config file (AppSettings section) and it's pretty simple with scalar types, but how to be with complex ones (IFormatProvider etc.). Does anybody know how to deal with that and is it possible at all?

I'm trying to simulate this example

ILogger logger = new LoggerConfiguration()
    .Enrich.WithExceptionDetails()
    .WriteTo.Sink(new RollingFileSink(
        @"C:\logs",
        new JsonFormatter(renderMessage: true))
    .CreateLogger();

but using app.config only.

Upvotes: 2

Views: 5292

Answers (1)

Nicholas Blumhardt
Nicholas Blumhardt

Reputation: 31832

You can use something like JsonRollingFile for this.

<configuration>
  <appSettings>
    <add key="serilog:using:Json" value="Serilog.Sinks.Json" />
    <add key="serilog:write-to:JsonRollingFile.pathFormat" value="C:\Logs\myapp-{Date}.jsnl" />
  </appSettings>
</configuration>

Upvotes: 2

Related Questions