Jeroen
Jeroen

Reputation: 63760

Configure RollingFile writer in 4.x version of Serilog.Sinks.File

The RollingFile sink was slipstreamed into Serilog.Sinks.File from version 4.x onward (as far as I can tell). I'm trying to configure it via appSettings like, but no log files are showing up...

Here's a repro.

  1. Create a new .NET 4.6.2 Framework Console Application
  2. Install-Package Serilog
  3. Install-Package Serilog.Sinks.File
  4. Install-Package Serilog.Settings.AppSettings
  5. Add this to App.config:
<appSettings>
  <add key="serilog:using:RollingFile" value="Serilog.Sinks.File" />
  <add key="serilog:write-to:RollingFile" />
  <add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message}{NewLine}{Exception}"/>
  <add key="serilog:write-to:RollingFile.pathFormat" value="log-{Date}.txt" />
</appSettings>
  1. Add this to Main in Program.cs:
Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger();
Log.Logger.Fatal("Does it work!?");
  1. Run it!

After that:

If I change RollingFile to File everywhere in the XML, and pathFormat to path, a file is placed in the expected location.

What am I doing wrong?

Upvotes: 2

Views: 1684

Answers (1)

Jeroen
Jeroen

Reputation: 63760

Wups, you need to use write-to:File everywhere now, and specify a rollingInterval on the File sink.

Found that this works:

<appSettings>
  <add key="serilog:using:File" value="Serilog.Sinks.File" />
  <add key="serilog:write-to:File" />
  <add key="serilog:write-to:File.outputTemplate" value="{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message}{NewLine}{Exception}"/>
  <add key="serilog:write-to:File.path" value="log-.txt" />
  <add key="serilog:write-to:File.rollingInterval" value="Hour" />
</appSettings>

Upvotes: 2

Related Questions