title: How to set log4net context property specific to an ASP.NET request?
body: <p>I've been using log4net to log our ASP.NET web site's log messages, and lately I wanted to add information about the page/handler where the error happened. I decided therefore to add the following line to Global.asax:</p>
  
  <pre><code>void Application_BeginRequest(object sender, EventArgs e)
  {
      log4net.ThreadContext.Properties["page"] = HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath;
  }
  </code></pre>
  
  <p>and like wise I added <code>%property{page}</code> to my conversion pattern:</p>
  
  <pre><code>&lt;conversionPattern value="%newline%date %-5level %property{page} - %message%newline%newline%newline" /&gt;
  </code></pre>
  
  <p>This worked fine for single requests. But then I noticed in my logs that the page property may change during an ASP.NET request. I have logging in one ASHX handler, and in the midst of its processing, the page property would change to a different value that points to an ASPX page. I concluded that there is another request coming to ASP.NET and its <code>BeginRequest</code> gets executed and the static page property in <code>log4net.ThreadContext</code> gets changed to another value.</p>
  
  <p>Now, I would like to maintain the page property per request, so that I can have the path of the executing page logged to the log consistently. I tried to find an answer, but I came out with nothing. What is the recommended way to solve this problem? I'm sure this is very basic functionality of web server event logging.</p>