user1312242
user1312242

Reputation: 337

Tracer Class for Automatic Logging of Method Entry and Exit

I want tracing in every function Entry and Exit. Say my class contains three methods MethodA MethodB MethodC... Through the Instance someone called MethodA and methodA calls MethodB and MethodB calls methodC

public class test
{
   Public void MethodA()
   {
      MethodB();
   }
   public void MethodB()
   {
      // Some Operation
      MethodC();
   }
   public void MethodC()
   {
      //Some Operation
   }
}

Now when someone calls like test obj = new test(); and obj.MethodA(); I want the tracer to write in database something like "Entered MethodA" in next row "Entered MethodB" next row "Entered MethodC" and then "Exited MethodC" "Exited MethodB" and finally "Exited Method a"

My restriction is: I am not supposed to write this trace code in every method entry and exit. I want this to happen automatically. Just make a Key of App.config file to true and the tracer should start action and false means tracing disable.

This we want to debug a Live production application.

To do this we got two ways:

Wrap the instance of Test class with a policy using a Policy Injection Applicaiton block: create a policyhandler from ICallHandler then create a MatchingRule, in the MatchingRule read the app.config file and return true if Tracing is enabled else false.

Disadvantage of doing so is: Everytime we create an Instance of any class through the Policy container, the system will read the app.config file and then read the policies present in the configuration file even if the tracing is disabled... This may degrade performance...

We found another approach i.e. Tracer class present inside the Logging Application Block. It has something like Method Entry Method Exit functionality. http://www.michaelhamrah.com/blog/2010/02/performance-tracing-for-your-applications-via-enterprise-library/

Please provide some more Idea about Tracer class. Can my requirement fit to plug a Tracer class.

Many Thanks,

Suraj

Upvotes: 1

Views: 1490

Answers (0)

Related Questions