简体   繁体   English

Serilog - 日志文件的路径

[英]Serilog - path to log file

i am trying to start working with serilog. 我正在尝试开始使用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. 普通的RollingFile不符合我的需求(我需要计数像logs \\ 20160701-00002.txt),所以我想使用RollingFileAlternate作为接收器。

When using RollingFile i added 使用RollingFile时我添加了

  loggerInstance = new LoggerConfiguration()
                    .ReadFrom.AppSettings()

and was able to get the path from the App.config file with using: 并且能够使用以下命令从App.config文件获取路径:

  <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 : 现在我切换到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. 我尝试使用logsDirectory和logsFolder,因为https://github.com/BedeGaming/sinks-rollingfile的示例中都描述了这两个,但我的程序不会创建文件。

if I add to the Loggerconfiguration: 如果我添加到Logger配置:

        loggerInstance = new LoggerConfiguration()
            .ReadFrom.AppSettings()
            .WriteTo.RollingFileAlternate("..\\log")

the foldername will be used and the logfiles are put in this folder. 将使用foldername并将日志文件放在此文件夹中。

Can some one help me and tell me what i am missing? 有人能帮帮我,告诉我我错过了什么吗?

There may be a problem with the documentation; 文档可能存在问题; the argument is called logDirectory , not logsDirectory . 该参数称为logDirectory ,而不是logsDirectory So, you need: 所以,你需要:

<add key="serilog:write-to:RollingFileAlternate.logDirectory" value="..\Log" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM