Reputation: 63760
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.
Install-Package Serilog
Install-Package Serilog.Sinks.File
Install-Package Serilog.Settings.AppSettings
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>
Main
in Program.cs
:Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger();
Log.Logger.Fatal("Does it work!?");
After that:
/bin/debug
log-{date}.txt
file in /bin/debug
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
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