public void Intercept(IInvocation invocation)
        {
            MethodInfo methodInfo = invocation.MethodInvocationTarget;

            if (methodInfo == null)
            {
                methodInfo = invocation.Method;
            }

            //we take the most permissive log settings from the attributes we find
            //If there is at least one attribute, the call gets wrapped with a transaction
            var assemblyLogAttributes =
                (LogAttribute[])methodInfo.ReflectedType.Assembly.GetCustomAttributes(typeof(LogAttribute), false);
            var classLogAttributes =
                (LogAttribute[])methodInfo.ReflectedType.GetCustomAttributes(typeof(LogAttribute), false);
            var methodLogAttributes =
                (LogAttribute[])methodInfo.GetCustomAttributes(typeof(LogAttribute), false);

            if (assemblyLogAttributes.Length == 0 && classLogAttributes.Length == 0 && methodLogAttributes.Length == 0)
            {
                invocation.Proceed();
            }
            else
            {
                LogAttributeSettings logAttributeSettings = GetLoggingLevels(assemblyLogAttributes, classLogAttributes,
                                                                             methodLogAttributes);
                methodLogger.LogEntry(methodInfo, invocation.Arguments, logAttributeSettings.EntryLevel);
                try {
                    invocation.Proceed();
                }
                catch (Exception err) {
                    methodLogger.LogException(methodInfo, err, logAttributeSettings.ExceptionLevel);
                    throw;
                }
                methodLogger.LogSuccess(methodInfo, invocation.ReturnValue, logAttributeSettings.SuccessLevel);
            }
        }
Esempio n. 2
0
 public override void OnSuccess(MethodExecutionEventArgs eventArgs)
 {
     methodLogger.LogSuccess(eventArgs.Method, eventArgs.ReturnValue, SuccessLevel);
 }