I\'m new to log4net, so hopefully this is a really easy question for someone?!
I\'ve got log4net working with the RollingLogFileAppender for my web application. I\'
UPDATE (2014-06-12): Starting from log4net 1.2.11 you can use %aspnet-request{ASP.NET_SessionId} in conversion pattern for this purpose.
References: https://issues.apache.org/jira/browse/LOG4NET-87 http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
You should create Application_PostAcquireRequestState handler in Global.asax.cs (it is called in every request):
protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
log4net.ThreadContext.Properties["SessionID"] = Session.SessionID;
}
And add [%property{SessionID}] to conversionPattern.