注: NLog可以将日志记录在 数据库, 文件, 控制台, 以下只记录文件日志配置

1. WebAPI分Controller层级打印日志配置

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Info"
    internalLogFile="./logs/nlog-internal.log">
  <!--记录日志打印日志的路径-->
  <targets async = "true">
    <target name = "file" xsi:type="File" encoding="GBK" fileName="${basedir}/${shortdate}/  ${aspnetmvc-controller}_${shortdate}.txt " layout="${date:format=HH\:mm\:ss}|${level}|threadid=${threadid}|${message}" />
  </targets>
  <rules>
    <logger name = "*" minlevel="Debug" writeTo="file" />
  </rules>
</nlog>
View Code

相关文章: