title: log4net GlobalContext
body: <p>I'm trying to figure out how to set a per-user session using ThreadContext.Properties.</p>
  
  <p>When a user has logged in on a website the userid is stored in session. This value
  i then want to append to ThreadContext.Properties["UserID"] upon after successful login.</p>
  
  <p>I'm saving log entries to db using the adonetappender and i use the %property{userid} to retrieve the value. But sometimes this value reads null.</p>
  
  <p>So basically what i want is:</p>
  
  <p>1) Create the</p>
  
  <p><code> private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);</code></p>
  
  <p>on those pages that i want to log.</p>
  
  <p>2) Upon successful login i need to store in ThreadContext.Properties["UserID"] a value that is always there throughout the users session and can be utlized both from pages i log from and also from the Application_Error(...) in global_asax. What is the lifespan of this ThreadContext anyway? I can't really use GlobalContext as far as i know.</p>
  
  <p>3) I don't want to reassign the value on every log statement.</p>
  
  <p>Hope you'll understand where i'm going.</p>
  
  <p>//Daniel </p>