Tracing Recursively(?) with PolicyInjection Interceptor

Mar 4, 2009 at 7:11 PM

Hello. I am working on implementing a solution using the Logging Application Block to both log and trace as across my application. I would like to use AOP to recursively intercept and trace all methods in a stack walk, so as to not litter my code with tracing statements. However, in my TraceCallHandler, basically an implementor of ICallHandler, my Invoke() call never triggers PolicyInjection to call back recursively into the TraceCallHandler. I begin tracing like this:



private void btnTestTraceLog_Click(object sender, EventArgs e)
ITestClass LobjTest = new TestClass();
//LobjTest = PolicyInjection.Create<TestClass,ITestClass>();
LobjTest = PolicyInjection.Wrap<ITestClass>(LobjTest);

And my TestClass uses the AOP decoration:



public class TestClass : ITestClass

My question is whether you know of a way to have the tracing work recursively, so that if we're tracing Operation1(), which calls Operation2(), both methods are traced.

My TraceCallHandler follows below



public class TraceCallHandler : ICallHandler
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
LoggingSettings LoggingConfig = (LoggingSettings)ConfigurationManager.GetSection("loggingConfiguration");
if (LoggingConfig.TracingEnabled)
LoggingProvider LobjLP = new LoggingProvider();
MessageOptions LobjMessageOptions = new MessageOptions();
LobjMessageOptions.Severity =
//this writes the begin log message 
LobjLP.Write(message.Message, LcolExtendedProperties, LobjMessageOptions);
//this calls our method being traced
LobjMethodReturn = getNext().Invoke(input, getNext);

message.Title = "TracerExit";
message.Message =
new StringBuilder("End Trace, Method :").Append(methodName).ToString();
LobjLP.Write(message.Message, LcolExtendedProperties, LobjMessageOptions);