I’m using log4net to log errors/info for our website and it works great.
Is it possible to control the level of logging based on the user logged in/sessionid or something similar. Ie. a user rings us with a problem and we turn on detailed logging just for them so we can troubleshoot but only slow down that user with detailed logging?
Obviously I could code explicitly but I was wondering if there is anything built into log4net? Maybe by using the filters with global properties?
You should have a look at Filters, maybe write your own. Or make your own log appender which does the filtering for you.
filter:
and then implement the SkeletonFilter class as YourNameSpace.UserFilter
If you use window authentication and impersonation you can also use the log4net.Filter.PropertyFilter which allows you to filter on properties in the message. The user can be found by the UserId property: