Using Tracer and Unity Interception

Topics: Logging Application Block
Jul 12, 2011 at 7:31 PM


I'm using Enterprise Library 5.0 and Unity 2.0 and am logging in the Invoke method of the CallHandler like so ...

   public class LogCallHandler: ICallHandler

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
            Token thisUsersAuthenticationToken = null;
            Dictionary<string, object> extendedProperties;
            IMethodReturn result;

            foreach (object obj in input.Arguments)
                if ((obj as Token) != null)
                    thisUsersAuthenticationToken = obj as Token;

            if (thisUsersAuthenticationToken != null)

                if (thisUsersAuthenticationToken.TracingEnabled)
                    using (new Tracer("Trace", thisUsersAuthenticationToken.TokenID))
                        LogEntry logEntry = new LogEntry();
I have ActivityTracing set for the category "Trace" as so ...  
      <add switchValue="All" name="App">
          <add name="Flat File Trace Listener" />
      <add switchValue="ActivityTracing, Verbose" name="Trace">
          <add name="Flat File Trace Listener 2" />
      <add switchValue="All" name="Audit">
Unfortunately the output of the trace isn't exactly what I'm looking for.  
In the message the method name for the entry and exit trace logs is set to the Invoke
method on the CallHandler (i.e. Message: End Trace: Activity '3aad9793-3ccb-4012-9953-917c0cfcdb94' in method 
'WCFExtensions.LogCallHandler.Invoke' at 357764461585 ticks (elapsed time: 1.78 seconds)).  Is there some way
of having the tracer output the method that is being intercepted instead?
Jul 13, 2011 at 4:51 AM


Unfortunately, the current behavior of tracer is that it will output the method name where the tracer has been defined. The only workaround I can think of is to use the normal logging instead, though you will lose some of the Tracer's features like the calculated elapsed time.


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.