天天看点

NLog基础配置

<?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"
      internalLogLevel="Warn"
      internalLogFile="internal-nlog.txt">

  <!-- define various log targets -->
  <targets>
    <!-- write logs to file -->
    <target xsi:type="File" name="web-post" fileName="D:\logs\logapi\POST\ux-${shortdate}.log" layout="${message}"  >
      <header>#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken</header>
    </target>

    <target xsi:type="File" name="web-get" fileName="D:\logs\logapi\W3SVC7\ux-${shortdate}.log" layout="${message}" >
      <header>#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken</header>
    </target>

    <target xsi:type="File" name="allfile" fileName="D:\logs\logapi\nlog-${shortdate}.log"
            layout="${longdate}|${logger}|${uppercase:${level}}|  ${message} ${exception}"  >
    </target>
  </targets>

  <rules>
    <logger name="web-post" minlevel="Trace" writeTo="web-post" />
    <logger name="web-get" minlevel="Trace" writeTo="web-get" />
    <!--All logs, including from Microsoft-->
    <logger name="allfile" minlevel="Trace" writeTo="allfile" />
  </rules>
</nlog>