0

I have a MVC3 web application. I am using Ninject 2 for dependency injection and the Ninject logging extension with log4net for logging.
My client wants to be able to "trace" a user session in Production to troubleshoot possible problems. The way we wanted to implement it is by dynamically changing the log level for that user, for example by storing a cookie so when Ninject.logging provides the logger instance, it knows to provide a log instance with level set to Debug.
I didn't find any way to do this, either by using Ninject logging or plain log4net.
Any suggestions?

Guillermo Vasconcelos
  • 1,701
  • 2
  • 17
  • 30

2 Answers2

1

I think you can force the level programmatically as described in this other question. It is not exactly providing a new logegr instance, but changing the current, but I suppose it can solve your problem.

Community
  • 1
  • 1
Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • That's part of the answer, I need to change the log level. The problem is that if I do that it will be changed for all subsequent request in the system. What I want is a way to change the level only for the requests that come with a cookie or parameter or something in the session. – Guillermo Vasconcelos Jun 01 '12 at 14:00
  • create a new log with LogManager.GetLogger() and make it append in the same appender of the original one... – Felice Pollano Jun 01 '12 at 14:06
1

We ended up modifying the ninject.extension.logging in this way:
- In LoggerFactoryBase we modified the GetLogger(IContext context) method to retrieve a cookie from the HttpContext
- If this value is set, we get or create the logger with "Tracing." + type name
- In log4net config we have a logger called "Tracing" set to Debug

Guillermo Vasconcelos
  • 1,701
  • 2
  • 17
  • 30