FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

NLog/src/NLog.Targets.AtomicFile at dev · NLog/NLog · GitHub

/ NLog Public

Latest commit

 

History

History

README.md

NLog AtomFile Target

NLog File Target extension that uses operating-system append semantics, allowing multiple processes to write concurrently to the same file.

AtomicFileTarget extends NLog's standard FileTarget and uses native operating-system file APIs to provide atomic append semantics:

  • Windows: uses FILE_APPEND_DATA together with SYNCHRONIZE.
  • Linux and macOS: uses open() with O_APPEND and O_CLOEXEC.
    • O_APPEND ensures that each write is positioned at the end of the file by the operating system.
    • O_CLOEXEC prevents the file descriptor from being unintentionally inherited across exec().

If having trouble with output, then check NLog InternalLogger for clues. See also Troubleshooting NLog

See the NLog Wiki for available options and examples.

Register Extension

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>();
});

Example Configuration:

<nlog>
<extensions>
    <add assembly="NLog.Targets.AtomicFile"/>
</extensions>
<targets>
  <target xsi:type="AtomFile"
          name="logfile"
          fileName="${basedir}/logs/application.log"
          layout="${longdate}|${level:uppercase=true}|${message} ${exception:format=tostring}" />
</targets>
</nlog>

Back | FazBrowse Home | New Git URL