NLog configuration file to log like Log4Net.

Here is a NLog config file that generates a similar log file layout as with the (default) Log4Net settings.

This NLog configuration also includes the date in the log file name to mimic the Log4Net ‘rollingFileAppender’ behavior.

file: NLog.config

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true">

  <targets>
    <target name="logfile" xsi:type="File" fileName="C:ProjectslogsMainLog.${shortdate}.log" layout="${level:padding=-6}  ${threadid:padding=-4} ${processid}   ${longdate}  ${logger:shortName=true:padding=-24} ${message} ${exception:format=ToString,StackTrace}"/>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="logfile" />
  </rules>

</nlog>

Share Your Thoughts