title: How to use Log4Net utility for logging into database using c#
body: <p>Currently in my project log4net is used to log all the exception, information, warnings etc. to a text file, but now what I want is to log all these details into database table instead of file.<br>
  Please help me to do this.</p>
  
  <p>Many thanks in advance.</p>
  
  <p>Configuration:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;log4net&gt;
    &lt;root&gt;
      &lt;level value="DEBUG" /&gt;
      &lt;appender-ref ref="ADONetAppender" /&gt;
    &lt;/root&gt;
    &lt;appender name="ADONetAppender" type="log4net.Appender.ADONetAppender"&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="server=xxxx; uid=xxxx; pwd=xxxx; database=xxxx" /&gt;
      &lt;commandText value="INSERT INTO log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" /&gt;
      &lt;parameter&gt;
        &lt;parameterName value="@log_date"/&gt;
        &lt;dbType value="DateTime"/&gt;
        &lt;layout type="log4net.Layout.RawTimeStampLayout"/&gt;
      &lt;/parameter&gt;
      &lt;parameter&gt;
        &lt;parameterName value="@thread"/&gt;
        &lt;dbType value="String"/&gt;
        &lt;size value="255"/&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%thread"/&gt;
        &lt;/layout&gt;
      &lt;/parameter&gt;
      &lt;parameter&gt;
        &lt;parameterName value="@log_level"/&gt;
        &lt;dbType value="String"/&gt;
        &lt;size value="50"/&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%level"/&gt;
        &lt;/layout&gt;
      &lt;/parameter&gt;
      &lt;parameter&gt;
        &lt;parameterName value="@logger"/&gt;
        &lt;dbType value="String"/&gt;
        &lt;size value="255"/&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%logger"/&gt;
        &lt;/layout&gt;
      &lt;/parameter&gt;
      &lt;parameter&gt;
        &lt;parameterName value="@message"/&gt;
        &lt;dbType value="String"/&gt;
        &lt;size value="4000"/&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%message"/&gt;
        &lt;/layout&gt;
      &lt;/parameter&gt;
      &lt;parameter&gt;
        &lt;parameterName value="@exception"/&gt;
        &lt;dbType value="String"/&gt;
        &lt;size value="2000"/&gt;
        &lt;layout type="log4net.Layout.ExceptionLayout"/&gt;
      &lt;/parameter&gt;
    &lt;/appender&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <p>Code in .cs file:</p>
  
  <pre><code>private log4net.ILog log = log4net.LogManager.GetLogger(typeof(ImportGlobalIPVData));
  log.Error("This is Error");
  </code></pre>
  
  <p>But nothing gets inserted into log table after using above code.</p>