You can define a username (or any other), for example:
this.SetThreadContext("UserName", userName);
Assuming userName contains the username.
Edit (what you really want to do):
Write a wrapper for log4net (with an interface) and make some method, for example. SetUserName as follows:
public void SetUserName(Func<string> getUserName)
You call this method when the application starts, and you pass some method that returns the current user (from the HttpContext). You will need to store the delegate somewhere, maybe a static variable. Then you have methods for logging at different levels, and each method calls a delegate ( Func<string> getUserName ) and sets the thread context property, as shown above. Thus, you do not need to set the context property of the stream manually before each call to the registrar ...
source share