views:

185

answers:

1

My ASP.NET site is using Integrated Authentication with impersonation turned off. I have added a "%username" to my "conversionPattern" in the web.config to add the user name to each logging entry. However this will use the application pool identity's user name, and not the current visiting user's name.

Any ideas on how best to do this? Do I have to write a custom appender? I don't mind any minor performance penalties as this is a small intranet site. Thanks!

+3  A: 

An alternative (and easier) solution you may want to take a look at is to use the ThreadContext class (formerly implemented as the MDC and NDC classes). You could have something like this inside an HttpModule (before the request arrives at your page) or anywhere else before you log your first message:

ThreadContext.Properties["user"] = username;

And then include the following in your conversionPattern:

%property{user}
Ronald Wildenberg
Thanks! I've created a HttpModule like you suggested and added that bit of code to the PostAuthorizeRequest event.
chuanose