Nlog suddenly stopped creating log files on Linux,

2019-09-14 18:25发布

问题:

My application is pointing to .net core framework 1.1.1.

I have added NLog to my project.

NLog - 5.0.0-beta05

NLog.Config - 4.3.9

NLog.Extensions.Logging - 1.0.0-rtm-beta1

My NLog config file is as follows:

<target name="infoInstrumentation"
      xsi:type="File"
      concurrentWrites="false"
    archiveFileName="/home/ubuntu/Desktop/Logs/Punu/ServiceInstrumentation.${shortdate}.{##}.log"
      archiveAboveSize="1000000"
      archiveNumbering="Rolling"
      maxArchiveFiles="10"
      fileName="/home/ubuntu/Desktop/Logs/Punu/ServiceInstrumentation.${shortdate}.log"
      layout="Timestamp: ${date}${newline}${all-event-properties:format=[key]\: [value]:separator=\&#xD;&#xA;}${newline}Message: ${message}${newline}Machine: ${machinename}${newline}${newline}${LayoutFooter}"
      keepFileOpen="false">
    </target>

Logging works on windows, but when I test code on Linux, it fails to write. Few days before it was working with Linux, but now it has stopped completely.

回答1:

As it looks like a problem with NLog library, you may try to troubleshoot NLog. For example, you may enable NLog internal logging and check if there are any problems.

Modify NLog config: add the following attributes into <nlog> section

internalLogLevel="Warn"
internalLogFile="internal-nlog.txt"

Look into Logging-troubleshooting NLog wiki for more examples, especially read "Internal logging" section.

Maybe you have the same problem, discussed here (issue on github): Unable to create/write to log on linux server using NLog 5.0.0-beta01 + beta02



回答2:

Make sure your configuration filename is exactly "NLog.config". Other casing will work on Windows, but Linux has case-sensitive filenames.