【问题标题】:Why does this NLog configuration not archive?为什么这个 NLog 配置不归档?
【发布时间】:2015-02-16 19:02:29
【问题描述】:

这个 NLog 配置有什么问题?为什么没有在“c:\TempFiles\AppLogs”中创建归档日志?奇怪的是,它似乎适用于 archiveEvery="Minute"。怎么回事?

<?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="Debug" internalLogFile="../logs/nlog.log" throwExceptions="true">

  <!-- make sure to set 'Copy To Output Directory' option for this file -->
  <!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->

  <extensions>
    <add assembly="NGinnBPM.MessageBus"/>
  </extensions>
  <variable name="logDir" value="${basedir}/logs"/>
  <variable name="LogsLocation" value="c:\TempFiles\AppLogs" />

  <targets>
    <target name="err" xsi:type="File"
            archiveFileName="${LogsLocation}\logs\contact_errors.{#}.txt"
            archiveEvery="Day"
          archiveNumbering="Rolling"
          maxArchiveFiles="30"
          concurrentWrites="true"
            fileName="${logDir}/contact_errors.${shortdate}.log" layout="${time}|T${threadid}|M${mdc:nmbrecvmsg}|${level}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}" />
    <target name="nginn" xsi:type="File"
            archiveFileName="${LogsLocation}\logs\contact_nginn.{#}.txt"
            archiveEvery="Day"
          archiveNumbering="Rolling"
          maxArchiveFiles="30"
          concurrentWrites="true"
            fileName="${logDir}/contact_nginn.${shortdate}.log" layout="${time}|T${threadid}|M${mdc:nmbrecvmsg}|${level}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}" />
    <target name="all" xsi:type="File"
            archiveFileName="${LogsLocation}\logs\contact.{#}.txt"
            archiveEvery="Day"
          archiveNumbering="Rolling"
          maxArchiveFiles="30"
          concurrentWrites="true"
            fileName="${logDir}/contact.${shortdate}.log" layout="${time}|T${threadid}|M${mdc:nmbrecvmsg}|${level}|${logger}|${message}"/>

  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="all" />
    <logger name="Slate.*" minlevel="Trace" writeTo="all" final="true"/>
    <logger name="*" minlevel="Error" writeTo="err" />
    <logger name="NGinnBPM.*" minlevel="Trace" writeTo="nginn" final="true"/>

  </rules>
</nlog>

【问题讨论】:

  • 目录c:\TempFiles\AppLogs 是否已经存在?您检查过logs/nlog.log 是否有错误?
  • 是的,是的 - 文件夹是空的

标签: configuration nlog


【解决方案1】:

所有目标的所有文件名都包含表达式${shortdate},因此每天都会创建一个新的日志文件。

所有目标的存档周期设置为Day,它应该每天存档日志文件(存档并清空当前日志文件)。

由于每天都会创建一个新的日志文件,因此当前的日志文件永远不会超过一天。因此,没有要归档的内容。

您可以更改日志的文件名(省略日期,因为如果您使用归档,则它没有用处),或者确保归档间隔短于日志文件的生命周期(为了测试,只需尝试将其设置为Minute)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多