FileTarget with support for atomic append where multiple processes can write to the same file
$ dotnet add package NLog.Targets.AtomicFileNLog File Target writing to file using operating system API for atomic file appending (O_APPEND), so multiple processes can write concurrently to the same file.
If having trouble with output, then check NLog InternalLogger for clues. See also Troubleshooting NLog
See the NLog Wiki for available options and examples.
Linux requires platform specific publish for Mono.Posix.NETStandard nuget-package:
dotnet publish with --framework net8.0 --configuration release --runtime linux-x64
NLog will only recognize type-alias AtomFile when loading from NLog.config-file, if having added extension to NLog.config-file:
<extensions>
<add assembly="NLog.Targets.AtomicFile"/>
</extensions>
Alternative register from code using fluent configuration API:
LogManager.Setup().SetupExtensions(ext => {
ext.RegisterTarget<NLog.Targets.AtomicFileTarget>();
});