Is it possible to extend the Controller type in Asp.net MVC to make a method available to all controller classes for application logging?
I've tried this:
public static class ControllerExtensions
{
public static ILog Log(this Controller controller)
{
log4net.Config.XmlConfigurator.Configure();
return log4net.LogManager.GetLogger(controller.GetType());
}
}
But, if I try to access the method as in:
Controller.Log.Info("hello");
It won't compile with the error message: 'System.Web.Mvc.Controller' does not contain a definition for 'Log'
I do have a using statement bringing the static class into scope.
Any help would be great.
Jacques