I'm trying to figure out how to set a per-user session using ThreadContext.Properties.
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.
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.
So basically what i want is:
1) Create the
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
on those pages that i want to log.
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.
3) I don't want to reassign the value on every log statement.
Hope you'll understand where i'm going.
//Daniel