views:

704

answers:

3

Hi All

I want to ask, how to use policy injection application block to log methods entry and exit in these cases :

Case1 : in case of logging events handlers of a web form controls, you know the class let's say _Default must be inherited from class System.Web.UI.Page , so we can't inherit our class from MarshalByRefObject class so logging will not work.

Case2 : in case we have a static class and we have to log the methods within, what we can do to inherit this class from MarshalByRefObject calss, in order to get logging works.

+1  A: 

It sounds to me like they have some stupid requirements to be able to apply logging... This may be an offtopic, but you might want to look at Spring.AOP framework to apply logging to your objects without the need to inherit from MarshalByRefObject. (In multiple-inheritance-amputated languages it is an annoying and drastic requirement I think).

badbadboy
A: 

Regarding Case 1, policy injection block is able to act on objects for which you have an interface. Easy enough to do in Visual Studio by using the Refactor->Extract Interface action, if you don't write with interfaces in mind already.

Ilya Tchivilev
A: 

Regarding Case 2, your "static" class could not really be a static class. It could inherit from MarshalByRefObject or implement an interface that you specify. It could then have a private constructor and a singleton instance that you policy-inject. All of your static methods would just call corresponding (policy-injected) instance methods on the singleton instance of the class.

John Bledsoe