Phil Helix
Phil Helix

Reputation: 3723

Why does this NLog configuration not archive?

What is wrong with this NLog configuration? Why aren't the archive logs created in "c:\TempFiles\AppLogs"? Oddly, it seems to work for archiveEvery="Minute". What's going on?

<?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>

Upvotes: 5

Views: 2013

Answers (1)

marapet
marapet

Reputation: 56446

All the filenames of all targets contain the expression ${shortdate}, therefore a new logfile is created every day.

The archive period for all targets is set to Day which ought to archive the log file every day (archive and empty current log file).

Since a new logfile is created every day, the current logfile is never older than one day. Therefore, there is nothing to archive.

You could either change the filename of the log (omit the date since it isn't useful if you use archiving), or make sure that the archiving interval is shorter than the lifespan of the logfile (for testing, simply try to set it to Minute).

Upvotes: 7

Related Questions