Is it possible whilst an application (of any type e.g. console, web, web role in azure etc.) to switch castle windsor interceptors on or off to avoid an application restart?
My scenario is to use an Interceptor like that below, to log method entry and exit with arguments.
public class ExampleInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Debug.WriteLine(string.Format("Before method: {0}", invocation.Method.Name));
invocation.Proceed();
Debug.WriteLine(string.Format("After method: {0}", invocation.Method.Name));
}
}
My initial approach was to do something like this:
public class InterceptorSelector : IModelInterceptorsSelector
{
public static bool InterceptorOn = false;
public bool HasInterceptors(ComponentModel model)
{
return
typeof(ExampleInterceptor) != model.Implementation
&& InterceptorOn
&& model.Implementation.Namespace.StartsWith("MvcApplication1");
}
public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors)
{
return new[]
{
InterceptorReference.ForType<ExampleInterceptor>()
};
}
}
However I found that once the interceptor has handled a method once, there must be some internal caching (for performance benefit no doubt) as the method does not get hit again in the InterceptorSelector.
The primary use case I have for this is a WebApi hosted in azure serving hundreds (if not 1000s) of requests per second over multiple VM instances. In the event of needing to debug the live environment I want to enable verbose logging on one of these instances but at the same time not want to take the VM instance out of action when enabling this logging.