title: log4net different messages for different appenders, creating duplicate log entries in file
body: <p>I have implemented a custom appender for log4net in which i am doing logging to a file and sending out mail. I want to log different message strings for each case. Below code creates two log entries in the file, one with appended string &amp; one without appended string. It also sends out the email without the appended string. </p>
  
  <pre><code>public static void Log(this ILog log, Level level, string message)
  {
      var token = string.Format("{0},{1},{2}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, level, message);
      int count = _tokenTimeThrottler.CheckAllow(token);
      if (count &gt;= 0)
      {
          //only to file logger, with an appended string
          log = LogManager.GetLogger("LogFileAppender");
          log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, level, count &lt;= 1 ? message : count + " counts of: " + message, null);
      }
  
      //only to mail
      log = LogManager.GetLogger("MyMailAppender");
      log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, level, message, null);
      }
  </code></pre>
  
  <p>But I want to don't want to log to file when I am doing.</p>
  
  <pre><code>//only to mail
  log = LogManager.GetLogger("MyMailAppender");
  log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, level, message, null);
  </code></pre>
  
  <p>My Config file, one appender is added using config file, the other appender is a dll so its added at runtime.</p>
  
  <p>1st appender:</p>
  
  <pre><code>&lt;log4net&gt;
      &lt;root&gt;
        &lt;level value="INFO" /&gt;
        &lt;appender-ref ref="LogFileAppender" /&gt;
      &lt;/root&gt;
      &lt;appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
        &lt;file value="C:\git\logs\log.log" /&gt;
        &lt;appendToFile value="true" /&gt;
        &lt;rollingStyle value="Size" /&gt;
        &lt;maxSizeRollBackups value="5" /&gt;
        &lt;maximumFileSize value="10MB" /&gt;
        &lt;staticLogFileName value="true" /&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%d [%t] %-5p  %m%n" /&gt;
        &lt;/layout&gt;
      &lt;/appender&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <p>2nd appender (Added at runtime):</p>
  
  <pre><code>Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
        PatternLayout patternLayout = new PatternLayout { ConversionPattern = "%d [%t] %-5p %m%n" };
  
        MyMailAppender myAppender = new MyMailAppender 
        {
          Name = "MyMailAppender",
          Layout = patternLayout,
          Access = "ghjkgj",
          Threshold = Level.Info,
        };
  
        myAppender .ActivateOptions();
        hierarchy.Root.AddAppender(myAppender );
  
        hierarchy.Root.Level = Level.All;
        hierarchy.Configured = true;
  </code></pre>