title: log4net write single file for each call to log.info
body: <p>I have been using log4net to capture any exceptions which occur during my applications running, which is working perfectly, I then created my own static Method which was responsible for capturing the failed XML object which was intended to provide further reading to compliment the log entry.</p>
  
  <pre><code>public static void WriteReceiptToXml(Exception ex, string XmlReceipt)
  {
      if (XmlReceipt != null)
      {
          string filename = ConfigurationManager.AppSettings["XmlReceiptPath"] + "/ReceiptXml" + DateTime.Now.ToString("ddMMyyhhmmss") + ".xml";
          File.WriteAllText(filename, XmlReceipt);
          Logger.Error(string.Format("The Xml Receipt was written to {0}", filename));
      }
  
      else
          Logger.Error("The Xml Receipt was empty so no document was created. Please reference the Payment request XML");
  }
  </code></pre>
  
  <p>This worked well, however a more experienced colleague suggested that <strong>this was abit of a code smell</strong> and that I was effectively re-inventing the wheel, as I am already using log4net this task should be handled by it too.</p>
  
  <p>At this point I created a new appender in the Web.config file (below) and filtered it on the INFO level, what I realised then was that as soon as I ran the application, log4net would create the XML file regardless of whether the catch block caught the exception and would leave it empty if no error occurred, which is obviously not what I want.</p>
  
  <pre><code>&lt;appender name="ReceiptXmlAppender" type="log4net.Appender.FileAppender" &gt;
    &lt;lockingModel type="log4net.Appender.FileAppender+MinimalLock" /&gt;
    &lt;file type="log4net.Util.PatternString" value="App_Data/ReceiptXml/Receipt-%date{yyyy-MM-dd_HH-mm-ss}.xml"/&gt;
    &lt;appendToFile value="false" /&gt;
    &lt;layout type="log4net.Layout.PatternLayout"&gt;
      &lt;conversionPattern value="%m" /&gt;
    &lt;/layout&gt;
    &lt;filter type="log4net.Filter.LevelRangeFilter"&gt;
      &lt;param name="LevelMin" value="INFO"/&gt;
      &lt;param name="LevelMax" value="INFO"/&gt;
    &lt;/filter&gt;
  &lt;/appender&gt;
  </code></pre>
  
  <p>In summary what I want is:</p>
  
  <ul>
  <li>log4net to only create the XML upon the INFO method being called in my catch block</li>
  <li>1 file to be created every time I call LOG.INFO</li>
  <li>The file must be datetime stamped</li>
  <li>I need to know the file name of the XML document created so that I can append this to actual log file as a supplement to the stack trace.</li>
  </ul>