Serilog - path to log file
There may be a problem with the documentation; the argument is called logDirectory
, not logsDirectory
. So, you need:
<add key="serilog:write-to:RollingFileAlternate.logDirectory" value="..\Log" />
Monika_Aydt
Updated on December 20, 2020Comments
-
Monika_Aydt over 3 years
i am trying to start working with serilog. The normal RollingFile doesn't fit my needs (i need the counting like logs\20160701-00002.txt), so i want to use the RollingFileAlternate as a sink.
When using RollingFile i added
loggerInstance = new LoggerConfiguration() .ReadFrom.AppSettings()
and was able to get the path from the App.config file with using:
<add key="serilog:minimum-level" value="Debug" /> <add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" /> <add key="serilog:write-to:RollingFile.pathFormat" value="..\Log\MyLOG.LOG" />
Now i switched to RollingFileAlternate :
<add key="serilog:minimum-level" value="Debug" /> <add key="serilog:using:RollingFileAlternate" value="Serilog.Sinks.RollingFileAlternate" /> <add key="serilog:write-to:RollingFileAlternate.logsDirectory" value="..\Log\test.log" /> <add key="serilog:write-to:RollingFileALternate.logsFolder" value="..\Log" />
I tried using logsDirectory and logsFolder since both are described in the examples of https://github.com/BedeGaming/sinks-rollingfile but my program won't create a file.
if I add to the Loggerconfiguration:
loggerInstance = new LoggerConfiguration() .ReadFrom.AppSettings() .WriteTo.RollingFileAlternate("..\\log")
the foldername will be used and the logfiles are put in this folder.
Can some one help me and tell me what i am missing?
-
Monika_Aydt over 7 yearsThank you! I needed to use "logDirectory". Now it is working.