title: logging exceptions to database using log4net
body: <p>I'm currently using log4net to log my messages and exceptions to database.
  I'm using this configuration:</p>
  
  <pre><code>&lt;appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender"&gt;
  
    &lt;bufferSize value="1" /&gt;
    &lt;connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
  
    &lt;connectionString value="Data Source=localhost\sqlexpress;Initial Catalog=LogDatabase;User ID=;Password=;"
                      providerName="System.Data.SqlClient" /&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;
  </code></pre>
  
  <p>The logging is working correctly except for the fact that I'm confused about something:
  If I log an exception using <code>log.Error(ex)</code> then the exception will be logged into the message column, however when I use <code>log.Error("Exception", ex)</code> then the message <code>Exception</code> will be logged to the message column while the exception will be logged to the exception column.
  I would like to be able to log my exception using  <code>log.Error(ex)</code> and to have the message column empty in that case and the exception logged to the actual exception column.</p>