Problem
To understand the real use of policy application blocks
we will take up a real time scenario. No application is perfect and it is very
much possible that you can have defects in production. In production as a rule
we have fully compiled DLL’s and it will be very difficult to track down the
errors. We can definitely use TRACE to get to the bottom of the problem. One of
the issues with TRACE is that we do not get verbose information. From trace we
will just get which method has the issues.
Below is a solution which I have thought I am sure there
are better ways of doing it. The whole point of this article is to make
understand how we can use the plug and play mechanism given by policy
application blocks.
We will try to implement a plug and play mechanism. The
application interface of our project calls business classes. When we want to
enable the debug mode we will just plug in the logging application block. The
logging application block will start logging in method calls in event log which
we can use to analyze what issue we have in the application. In the normal
production mode we will remove the logging feature. The below figure visualizes
the same as a switch
Which can plug in the logging or plug it out.
Solution
To implement the above solution we will use policy
application blocks. Policy application blocks helps us to plug in policies which
can be added and remove on fly. Using the enterprise application UI you can add
new policies or remove policies.
Implementation
In order that the class methods can be monitored by the
policy block we need inherit the class from an interface. For the current
example we want to monitor any methods of class clsFireMethods. You can see we
have inherited the same from a interface ‘IMethods’
|