We are attempting to load balance an ASP.NET Core MVC application that uses NLog to log using File Target. The load-balanced setup will have multiple application servers, and the plan is to store the logs in a network drive. We are reviewing the Performance Tuning Options in the following link
https://github.com/NLog/NLog/wiki/File-target
and came up with the following configuration.
<targets async="true">
<target type="File" name="logfile" fileName="${basedir}/logs/${level}.txt" keepFileOpen="false" networkWrites ="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
Are there any way to optimize the configuration. Any recommendation is highly appreciated
Thanks in advance
keepFileOpen="false"
andnetworkWrites="true"
have the same meaning, and NLog-project is moving towards marking networkWrites as obsolete to remove duplicate logic. So you should just usekeepFileOpen="false"
.If multiple applications are going to write to the same log-file-path, then you should also enable
concurrentWrites="true"
since it will applyconcurrentWriteAttempts="10"
. So when the shared log-file is momentarily locked by other application for log-writing, then retry-logic will be applied.But very good idea to apply
<targets async="true">
to avoid being hit by the network-outage.See also: https://github.com/NLog/NLog/wiki/File-target