Serilog - path to log file

36.8k views Asked by At

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?

1

There are 1 answers

1
Nicholas Blumhardt On BEST ANSWER

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" />