Skip to content

Instantly share code, notes, and snippets.

@mniak
Last active July 11, 2018 14:14
Show Gist options
  • Save mniak/c63aa2d97aa8afb9d709cf2317574917 to your computer and use it in GitHub Desktop.
Save mniak/c63aa2d97aa8afb9d709cf2317574917 to your computer and use it in GitHub Desktop.
My standard #nlog configs
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<variable name="company_name" value="MyCompany" />
<variable name="outdir" value="${specialfolder:folder=LocalApplicationData}/${var:company_name}/Logs/${var:program_name:default=Undefined}" />
<variable name="layout" value="${longdate} | ${pad:padding=-15:${threadname:whenEmpty=${threadid}}} | ${pad:padding=-5:${level:uppercase=true}} | ${logger} | ${message}${onexception:inner= | ${exception:format=tostring}}"/>
<targets>
<target name="file_full" xsi:type="File"
layout="${var:layout}"
fileName="${var:outdir}/full.log"
archiveFileName="${var:outdir}/full.{#}.log"
archiveEvery="Day"
archiveNumbering="Date"
maxArchiveFiles="7"
concurrentWrites="true"
/>
<target name="file_info" xsi:type="File"
layout="${var:layout}"
fileName="${var:outdir}/info.log"
archiveFileName="${var:outdir}/info.{#}.log"
archiveEvery="Day"
archiveNumbering="Date"
maxArchiveFiles="7"
concurrentWrites="true"
/>
<target name="file_error" xsi:type="File"
layout="${var:layout}"
fileName="${var:outdir}/error.log"
archiveFileName="${var:outdir}/error.{#}.log"
archiveEvery="Day"
archiveNumbering="Date"
maxArchiveFiles="7"
concurrentWrites="true"
/>
</targets>
<rules>
<logger name="*" writeTo="file_full" />
<logger name="*" minlevel="Info" writeTo="file_info" />
<logger name="*" minlevel="Error" writeTo="file_error" />
</rules>
</nlog>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<variable name="layout" value="${longdate} | ${pad:padding=-15:${threadname:whenEmpty=${threadid}}} | ${pad:padding=-5:${level:uppercase=true}} | ${logger} | ${message}${onexception:inner= | ${exception:format=tostring}}"/>
<targets async="true">
<target name="console" xsi:type="ColoredConsole"
layout="${var:layout}">
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="console" />
</rules>
</nlog>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<variable name="outdir" value="${basedir}/logs" />
<variable name="layout" value="${longdate} | ${pad:padding=-15:${threadname:whenEmpty=${threadid}}} | ${pad:padding=-5:${level:uppercase=true}} | ${logger} | ${message}${onexception:inner= | ${exception:format=tostring}}"/>
<targets async="true">
<target name="full" xsi:type="File"
layout="${var:layout}"
fileName="${var:outdir}/full.log"
archiveFileName="${var:outdir}/full.{#}.log"
archiveEvery="Day"
archiveNumbering="Date"
maxArchiveFiles="7"
concurrentWrites="true"
/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="full" />
</rules>
</nlog>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<variable name="outdir" value="C:\logs\OTHER" />
<variable name="layout" value="${longdate} | ${pad:padding=-15:${threadname:whenEmpty=${threadid}}} | ${pad:padding=-5:${level:uppercase=true}} | ${logger} | ${message}${onexception:inner= | ${exception:format=tostring}}"/>
<targets async="true">
<target name="file" xsi:type="File"
layout="${var:layout}"
fileName="${var:outdir}/full.log"
archiveFileName="${var:outdir}/full.{#}.log"
archiveEvery="Day"
archiveNumbering="Date"
maxArchiveFiles="7"
concurrentWrites="true"
/>
<target type="Network" name="splunk" address="udp://172.16.19.254:10000" layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=tostring}"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
<logger name="*" minlevel="Trace" writeTo="splunk" />
</rules>
</nlog>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment