首先添加negut包Nlog.Config:

Nlog.Config:日志方法步骤

安装完毕以后,可以替换Nlog.config

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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off"
      internalLogFile="c:\nlog\nlog-internal.log">

  <variable name="varDataFolderPath" value="${basedir}/logs"/>
  <variable name="varLayHeader" value="${longdate}|${level}"/>
  <variable name="varLayMiddle" value="${callsite-linenumber}|${callsite:includeSourcePath=false:methodName=false}"/>
  <variable name="varLayBack" value="${message}|${exception:format=toString}"/>
  <targets>
    <target name="logFile"
            xsi:type="File"
            encoding="utf-8"
            maxArchiveFiles="100"
            archiveEvery="Day"
            archiveNumbering="Date"
            archiveDateFormat="yyyyMMdd"
            archiveFileName="${varDataFolderPath}/archives/log.{#}.txt"
            fileName="${varDataFolderPath}/nlog.txt"
            layout="${varLayHeader}|${varLayMiddle}|${varLayBack}" />
    <target xsi:type="Console"
            name="logConsole"
            layout="${varLayHeader}|${varLayMiddle}|${varLayBack}" />
  </targets>
  <rules>
    <logger minlevel="Trace" name="*" writeTo="logFile" />
    <logger minlevel="Trace" name="*" writeTo="logConsole" />
  </rules>
</nlog>
View Code

相关文章:

  • 2022-12-23
  • 2021-10-13
  • 2021-05-06
  • 2022-12-23
  • 2022-12-23
  • 2023-03-19
  • 2022-02-27
猜你喜欢
  • 2021-12-15
  • 2021-11-27
  • 2021-10-06
  • 2022-02-08
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案