title: NLog rotate and cleanup logfiles
body: <p>Within my company we're working with NLog. We're experiencing issues with large amount of log files. What we want to do is archive files by day and keep a maximum of an x amount of files. Lets say 7. I've read several topics on the internet regarding this and they're mostly pointing me in the same direction of modifying my NLog.config file. However it doesn't seem to be willing to rotate the files as I expect it to do. Currently nothing is being archived in the desired folder. But all files are saved in the 'logs'-directory in the following format;</p>
  
  <pre><code>Log.info.2011-11-07.txt
  </code></pre>
  
  <p>Within my application i've got an directory 'logs'. Inside that folder all logfiles are saved. I've also got an folder called 'archives' in which I want to archive all older files. After the maximum number of log files is reached inside that directory they automatically should be cleaned. Is this possible? My current NLog.config file looks like below;</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        autoReload="true"
        throwExceptions="true"
        internalLogFile="C:\nlog-internal.txt"
        internalLogLevel="Error"&gt;
  
    &lt;extensions&gt;
      &lt;add assembly="NLog.Extended" /&gt;
    &lt;/extensions&gt;
  
    &lt;targets&gt;
      &lt;!-- will move file to archive once it reaches 1MB. Files are archived by day, with a maximum of three files. ConcurrentWrites is set to false, 
              change to true if multiple processes will be writing to the logfile--&gt;
      &lt;target name="file" xsi:type="File" fileName="${basedir}/logs/Log.info.${shortdate}.txt" 
              layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}"
              archiveFileName="${basedir}/logs/archives/log.info.${shortdate}.txt"
              archiveAboveSize="1048576"
              archiveEvery="Day"
              archiveNumbering = "Rolling"
              maxArchiveFiles="7"
              concurrentWrites="false"
              /&gt;
      &lt;target name="file-default" xsi:type="File" fileName="${basedir}/log_default.txt"/&gt;
      &lt;target name="file-debug" xsi:type="File" fileName="${basedir}/log_debug.txt"/&gt;
      &lt;target name="file-testclass" xsi:type="File" fileName="${basedir}/log_testclass.txt"/&gt;
      &lt;target name="mail" xsi:type="Mail" 
              subject="${level} - ${aspnet-request:serverVariabele=PATH_INFO} | ${callsite:includeSourcePath=true}" 
              to="someone@mail.com" 
              smtpServer="mail.server.com" 
              from="no-reply@errormail.com"/&gt;
      &lt;target xsi:type="Database" 
              name="TestDatabaseLogging" 
              connectionString="Data Source=123.123.123.123;Initial Catalog=NLog_Test;User ID=su_Nlog;Password=test123" 
              dbDatabase="NLog_Test"&gt;
        &lt;commandText&gt;
          insert into INNO_LOG ([createDate], [Origin], [LogLevel], [Message], [Exception], [StackTrace]) values (@createDate, @origin, @logLevel, @message, @exception, @stackTrace)
        &lt;/commandText&gt;
        &lt;parameter name="@createDate" layout="${date}"/&gt;
        &lt;parameter name="@origin" layout="${callsite}"/&gt;
        &lt;parameter name="@logLevel" layout="${level}"/&gt;
        &lt;parameter name="@message" layout="${message}"/&gt;
        &lt;parameter name="@exception" layout="${exception:format=Message,StackTrace}"/&gt;
        &lt;parameter name="@stackTrace" layout="${stacktrace}"/&gt;
      &lt;/target&gt;
  
    &lt;/targets&gt;
  
    &lt;rules&gt;
      &lt;logger name="*" minlevel="Fatal" writeTo="mail" /&gt;
      &lt;logger name="*" minlevel="Error" writeTo="TestDatabaseLogging" /&gt;
      &lt;logger name="*" minlevel="Debug" writeTo="file-debug" /&gt;
      &lt;logger name="*" minlevel="Info" writeTo="file" /&gt;
      &lt;!--Log to specific files for specific classes.--&gt;
      &lt;logger name="_Default" minlevel="Trace" writeTo="file-default" /&gt;
      &lt;logger name="TestClass" minlevel="Trace" writeTo="file-testclass" /&gt;
    &lt;/rules&gt;
  &lt;/nlog&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong>
  The final (snipped) solution after ckellers answer.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;target name="file"
              xsi:type="File"
              fileName="${basedir}/logs/Log.${level}.current.txt"
              layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}"
              archiveFileName="${basedir}/logs/archives/log.error.${shortdate}.{#}.txt"
              archiveAboveSize="5242880"
              archiveEvery="Day"
              archiveNumbering = "Rolling"
              maxArchiveFiles="3" /&gt;
  </code></pre>