Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AvalonWot/fc6590164e34cad86d26ee80b8d26332 to your computer and use it in GitHub Desktop.
Save AvalonWot/fc6590164e34cad86d26ee80b8d26332 to your computer and use it in GitHub Desktop.
NLog Configuration That Auto-Rotate with Config Section
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console" layout="${longdate} ${callsite} ${level} ${message}"/>
<target name="logfile" xsi:type="File" fileName="C:\temp\log.txt" layout="${longdate} ${callsite} ${level} ${message}"/>
<target name="rotatelog" xsi:type="File"
layout="${longdate} ${logger} ${message}"
fileName="c:/temp/logs/alogfile.txt"
archiveFileName="c:/temp/logs/log.{#}.txt"
archiveEvery="Day"
archiveNumbering="Rolling"
maxArchiveFiles="7"
concurrentWrites="true" />
</targets>
<rules>
<logger name="*" minLevel="Debug" writeTo="rotatelog"/>
<logger name="*" minLevel="Debug" writeTo="console"/>
</rules>
</nlog>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment