title: Log4Net Logging Variables
body: <p>Is it possible for log4net to log custom variables, or am I limited to the <a href="http://www.beefycode.com/post/log4net-tutorial-pt-4-layouts-and-patterns.aspx" rel="nofollow">"pre-configured" variables</a>? e.g. </p>
  
  <blockquote>
    <ul>
    <li>%appdomain: the friendly name of the appdomain from which the log entry was made</li>
    <li>%date:  the local datetime when the log entry was made</li>
    <li>%exception: a formatted form of the exception object in the log entry, if the entry contains an exception; otherwise, this format
    expression adds nothing to the log entry</li>
    <li>etc</li>
    </ul>
  </blockquote>
  
  <p>I need to log session information, from <code>ActionExecutedContext</code> for example. if that's relevant I call log4net from a Global Exception filter.</p>
  
  <p>Is it possible, if so, how?</p>
  
  <p>The currently configured appender, using only aforementioned "pre-configured" variables:</p>
  
  <pre><code>&lt;appender name="ADONetAppender" type="log4net.Appender.ADONetAppender"&gt;
        &lt;bufferSize value="1" /&gt;
        &lt;connectionType value="LALALA DELETED" /&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>