示例#1
0
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The method invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            if (!this.loggers.ContainsKey(invocation.TargetType))
            {
                lock (Mutex)
                {
                    if (!this.loggers.ContainsKey(invocation.TargetType))
                    {
                        this.loggers.Add(invocation.TargetType, factory.Create(invocation.TargetType.ToString()));
                    }
                }
            }
            ILoggerImplementation logger = this.loggers[invocation.TargetType];
            var info = new MethodTraceInfo()
            {
                MachineName         = Environment.MachineName,
                AppDomainName       = AppDomain.CurrentDomain.FriendlyName,
                ThreadIdentityName  = Thread.CurrentPrincipal.Identity.Name,
                WindowsIdentityName = WindowsIdentity.GetCurrent().Name,
                ClassName           = invocation.TargetType.Name,
                MethodName          = invocation.Method.Name,
                Dump = CreateInvocationLogInfo(invocation).ToString()
            };

            logger.TraceMethodCall(info);
            invocation.Proceed();
            logger.TraceEndMethodCall(info);
        }
 /// <summary>
 /// Intercepts the specified invocation.
 /// </summary>
 /// <param name="invocation">The method invocation.</param>
 public void Intercept(IInvocation invocation)
 {
     if (!this.loggers.ContainsKey(invocation.TargetType))
     {
         lock (Mutex)
         {
             if (!this.loggers.ContainsKey(invocation.TargetType))
             {
                 this.loggers.Add(invocation.TargetType, factory.Create(invocation.TargetType.ToString()));
             }
         }
     }
     ILoggerImplementation logger = this.loggers[invocation.TargetType];
     var info = new MethodTraceInfo()
     {
         MachineName = Environment.MachineName,
         AppDomainName = AppDomain.CurrentDomain.FriendlyName,
         ThreadIdentityName = Thread.CurrentPrincipal.Identity.Name,
         WindowsIdentityName = WindowsIdentity.GetCurrent().Name,
         ClassName = invocation.TargetType.Name,
         MethodName = invocation.Method.Name,
         Dump = CreateInvocationLogInfo(invocation).ToString()
     };
     logger.TraceMethodCall(info);
     invocation.Proceed();
     logger.TraceEndMethodCall(info);
 }
示例#3
0
        public void TestSingleCall()
        {
            SingleCall();

            var realResult     = _tracer.GetTraceResult().GetThread(0).GetMethod(0);
            var expectedResult = new MethodTraceInfo("SingleCall", className);

            Asserts(expectedResult, realResult);
        }
示例#4
0
        public void TestNestedCall()
        {
            OuterMethod();

            var realResult     = _tracer.GetTraceResult().GetThread(0).GetMethod(0);
            var expectedResult = new MethodTraceInfo("OuterMethod", className);

            expectedResult.Methods.Add(new MethodTraceInfo("InnerMethod", className));

            Asserts(expectedResult, realResult);
        }
示例#5
0
        public void TestRecursionCall()
        {
            string methodName = "Recursion";

            Recursion(1);

            var realResult     = _tracer.GetTraceResult().GetThread(0).GetMethod(0);
            var expectedResult = new MethodTraceInfo(methodName, className);

            expectedResult.Methods.Add(new MethodTraceInfo(methodName, className));
            expectedResult.GetMethod(0).Methods.Add(new MethodTraceInfo(methodName, className));

            Asserts(expectedResult, realResult);
        }
示例#6
0
 static void Asserts(MethodTraceInfo expectedResult, MethodTraceInfo realResult)
 {
     Assert.AreEqual(expectedResult.Name, realResult.Name);
     Assert.AreEqual(expectedResult.ClassName, realResult.ClassName);
     Assert.AreEqual(expectedResult.Methods.Count, realResult.Methods.Count);
 }