title: How can you write to a database log only when the level is WARN in log4net c#
body: <p>I want to write to a log file and a database using log4net.  However I only want to write to the database if the level is WARN.</p>
  
  <p>I have tried Threshold, level and filter in my config file.</p>
  
  <pre><code>&lt;log4net&gt;
    &lt;root&gt;
      &lt;appender-ref ref="ADONetAppender" /&gt;
      &lt;appender-ref ref="file" /&gt;
    &lt;/root&gt;
  
    &lt;appender name="ADONetAppender" type="log4net.Appender.ADONetAppender"&gt;
      &lt;filter type="log4net.Filter.LevelMatchFilter"&gt;
        &lt;levelToMatch value="WARN"/&gt;
      &lt;/filter&gt;
      &lt;bufferSize value="100"/&gt;
      &lt;connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/&gt;
      &lt;connectionString value="connString"/&gt;
      &lt;commandText value="APP_Insert_File_Failure" /&gt;
      &lt;commandType value="StoredProcedure" /&gt;
  
      &lt;parameter&gt;
        &lt;parameterName value="@FileName" /&gt;
        &lt;dbType value="String" /&gt;
        &lt;size value="255"/&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%property{FileName}" /&gt;
        &lt;/layout&gt;
      &lt;/parameter&gt;
  
      &lt;parameter&gt;
        &lt;parameterName value="@FileFailure" /&gt;
        &lt;dbType value="String" /&gt;
        &lt;size value="255"/&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%property{FileFailure}" /&gt;
        &lt;/layout&gt;
      &lt;/parameter&gt;
    &lt;/appender&gt;
  
    &lt;appender name="file" type="log4net.Appender.RollingFileAppender"&gt;
      &lt;param name="File" value="C:\Temp" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;rollingStyle value="Date" /&gt;
      &lt;datePattern value="yyyyMMdd" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
        &lt;conversionPattern value="%date %-5level %newline%message%newline%exception%newline" /&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <p>My C# code to run is </p>
  
  <pre><code>            //Parameters for stored procedure
              log4net.GlobalContext.Properties["FileName"] = Path.GetFileName(filename);
              log4net.GlobalContext.Properties["FileFailure"] = "Testing 1 2 3;
              log.Warn("Testing 1 2 3");
  </code></pre>
  
  <p>I use to populate the connString -</p>
  
  <pre><code>    public static void SetUpDbConnection(string adoNetAppenderString, string newConnString)
      {
          log4net.Repository.ILoggerRepository repository = log4net.LogManager.GetRepository();
          foreach (log4net.Appender.IAppender appender in repository.GetAppenders())
          {
              if (appender.Name.CompareTo(adoNetAppenderString) == 0 &amp;&amp; appender is log4net.Appender.AdoNetAppender)
              {
                  log4net.Appender.AdoNetAppender adoAppender = (log4net.Appender.AdoNetAppender)appender;
                  adoAppender.ConnectionString = System.IO.Path.Combine(adoAppender.ConnectionString, newConnString);
                  adoAppender.ActivateOptions();
              }
          }
      }
  </code></pre>
  
  <p>It writes to the text file no problem, but nothing is appearing in the database.</p>
  
  <p>I want it to write into the database when level = Warn</p>