NLog配置

 

1、archiveAboveSize 限制单个文件大小

<targets>
  <target name="MyFile"
          xsi:type="File"
          fileName="C:\Logs\MyApp.log"
          encoding="utf-8"
          layout="${date:format=yyyyMMddHHmmss} ${message}"
          archiveEvery="Day"
          archiveFileName="C:\Logs\MyApp.{#}.log"
          archiveNumbering="DateAndSequence" 
          archiveDateFormat="yyyy-MM-dd"
          archiveAboveSize="104857600"
          maxArchiveFiles="14" />
</targets>

 如下配置,100k一个文件

<targets async="true">

    <!--
    add your targets here
    See https://github.com/nlog/NLog/wiki/Targets for possible targets.
    See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
    -->

    <!--
    Write events to a file with the date in the filename.
    <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
            layout="${longdate} ${uppercase:${level}} ${message}" />
    -->
    <target xsi:type="AsyncWrapper" name="MyLogger">
      <target xsi:type="File"
              layout="${longdate},${uppercase:${level}},${message}"
              fileName="${basedir}/Log/${level}/${year}/${year_month}/${shortdate}.log" encoding="utf-8" archiveAboveSize="102400"/>
    </target>

    <target xsi:type="Null" name="blackhole" />
  </targets>

红框始终为最新

 

posted @ 2021-05-12 18:29  wjl910  阅读(292)  评论(0)    收藏  举报