title: log4cxx TimeBasedRollingPolicy with maximum number of files
body: <p>I am trying to programmatically create a log4cxx based <code>RollingFileAppender</code> with a <code>TimeBasedRollingPolicy</code> which also limits the maximum number of historic log files. I have it almost working except that the old files are never cleaned up. I cannot find how to specify the maximum number of old files to keep. I believe this should be equivalent to <code>SetMaxHistory</code> method in <code>RollingFileAppender</code> in log4j, but such a method does not exist in log4cxx. How can this be done?</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;log4cxx/patternlayout.h&gt;
  #include &lt;log4cxx/rolling/rollingfileappender.h&gt;
  #include &lt;log4cxx/rolling/timebasedrollingpolicy.h&gt;
  
  log4cxx::LoggerPtr create_history_logger()
  {
    log4cxx::helpers::Pool p;
  
    auto rollingPolicy = new log4cxx::rolling::TimeBasedRollingPolicy();
    const std::string fileName(&quot;/tmp/logs/history&quot;);
    log4cxx::LogString fileNamePattern = fileName + &quot;.%d{yyyy-MM-dd}.log&quot;;
    rollingPolicy-&gt;setFileNamePattern(fileNamePattern);
    // Does not compile - rollingPolicy-&gt;setMaxHistory(7);
    rollingPolicy-&gt;activateOptions(p);
  
    auto rollingFileAppender = new log4cxx::rolling::RollingFileAppender();
    rollingFileAppender-&gt;setName(&quot;MyHistoryAppender&quot;);
    rollingFileAppender-&gt;setRollingPolicy(rollingPolicy);
    rollingFileAppender-&gt;setLayout(log4cxx::LayoutPtr(new log4cxx::PatternLayout(&quot;%d{ISO8601} %m%n&quot;)));
    rollingFileAppender-&gt;setAppend(true);
    rollingFileAppender-&gt;activateOptions(p);
  
    auto my_logger(log4cxx::Logger::getLogger(&quot;MyHistoryLogger&quot;));
    my_logger-&gt;addAppender(rollingFileAppender);
    my_logger-&gt;setLevel(log4cxx::Level::getFatal());
    my_logger-&gt;setAdditivity(false);
  
    return my_logger;
  }
  </code></pre>