NLog安装:

Install-Package NLog

NLog配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler,NLog" />
  </configSections>

  <!--autoReload="true"表示在不重新启动应用程序的情况下,修改配置文件,NLog会自动加载应-->
  <!--NLog内部的日志消息写到应用程序目录下的logs文件夹里的internalLog.txt文件中;(-->
  <nlog autoReload="true" internalLogLevel="Trace" internalLogFile="logs/internalLog.txt">
    <targets>
      <!--文件输出(type="File")-->
      <target name="FileOutput" type="File" fileName="${basedir}/logs/${shortdate}.log"
              layout="${longdate} ${callsite} ${level}:
              ${message} ${event-context:item=exception} ${stacktrace} ${event-context:item=stacktrace}" />
      <!--控制台输出(type="File")-->
      <target name="ConsoleOutput" type="Console" layout="${date:format=yyyy-MM-dd HHmmss} ${callsite} ${level} ${message}"></target>
    </targets>
    <rules>
      <!--<logger name="Test" minlevel="Debug" maxlevel="Error" writeTo="FileOutput,ConsoleOutput" />-->
      <logger name="*" minlevel="Debug" maxlevel="Error" writeTo="FileOutput,ConsoleOutput" />
    </rules>
  </nlog>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>
View Code

相关文章:

  • 2022-03-02
  • 2021-05-18
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2022-01-02
相关资源
相似解决方案