public void Intercept(IInvocation invocation)
        {
            // BEFORE the target method execution
            var methodInput = CreateMethodInput(invocation);

            var(msgInputLog, correlationState) = _methodLogMessageFactory.CreateInputMethodLogMessage(methodInput);

            _logger.Info(msgInputLog);

            try
            {
                // Yield to the next module in the pipeline
                invocation.Proceed();

                // AFTER the target method execution
                var msgOutputLog = _methodLogMessageFactory.CreateOutputMethodLogMessage(new MethodReturn {
                    ReturnValue = invocation.ReturnValue
                }, correlationState);

                _logger.Info(msgOutputLog);
            }
            catch (Exception exp)
            {
                var msgOutputLog = _methodLogMessageFactory.CreateOutputMethodLogMessage(new MethodReturn {
                    Exception = exp
                }, correlationState);

                _logger.Error(msgOutputLog);

                throw;
            }
        }
Example #2
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            // BEFORE the target method execution
            var methodInput = CreateMethodInput(input);

            var(msgInputLog, correlationState) = _methodLogMessageFactory.CreateInputMethodLogMessage(methodInput);

            _logger.Info(msgInputLog);

            // Yield to the next module in the pipeline
            var methodReturn = getNext().Invoke(input, getNext);

            // AFTER the target method execution
            var msgOutputLog = _methodLogMessageFactory.CreateOutputMethodLogMessage(new MethodReturn {
                ReturnValue = methodReturn.ReturnValue, Exception = methodReturn.Exception
            }, correlationState);

            if (methodReturn.Exception == null)
            {
                _logger.Info(msgOutputLog);
            }
            else
            {
                _logger.Error(msgOutputLog);
            }

            return(methodReturn);
        }
        protected override async Task InterceptAsync(IInvocation invocation, Task proceed)
        {
            // BEFORE the target method execution
            var methodInput = CreateMethodInput(invocation);

            var(msgInputLog, correlationState) = _methodLogMessageFactory.CreateInputMethodLogMessage(methodInput);

            _logger.Info(msgInputLog);

            try
            {
                // Yield to the next module in the pipeline
                await proceed.ConfigureAwait(false);

                // AFTER the target method execution
                var methodReturn = new MethodReturn {
                    ReturnValue = "Void`"
                };

                var msgOutputLog = _methodLogMessageFactory.CreateOutputMethodLogMessage(methodReturn, correlationState);

                _logger.Info(msgOutputLog);
            }
            catch (Exception exp)
            {
                var methodReturn = new MethodReturn {
                    Exception = exp
                };

                var msgOutputLog = _methodLogMessageFactory.CreateOutputMethodLogMessage(methodReturn, correlationState);

                _logger.Error(msgOutputLog);

                throw;
            }
        }
        public async Task <IMethodInvocationResult> InterceptAsync(IAsyncMethodInvocation methodInvocation)
        {
            // BEFORE the target method execution
            var methodInput = CreateMethodInput(methodInvocation);

            var(msgInputLog, correlationState) = _methodLogMessageFactory.CreateInputMethodLogMessage(methodInput);

            _logger.Info(msgInputLog);

            try
            {
                // Yield to the next module in the pipeline
                var result = await methodInvocation.InvokeNextAsync().ConfigureAwait(false);

                // AFTER the target method execution
                var methodReturn = new MethodReturn {
                    ReturnValue = result.ReturnValue
                };

                if (methodInvocation.ActualReturnType.Name == "Void")
                {
                    methodReturn.ReturnValue = "Void";
                }

                var msgOutputLog = _methodLogMessageFactory.CreateOutputMethodLogMessage(methodReturn, correlationState);

                _logger.Info(msgOutputLog);

                return(result);
            }
            catch (Exception e)
            {
                var methodReturn = new MethodReturn {
                    Exception = e
                };

                var msgOutputLog = _methodLogMessageFactory.CreateOutputMethodLogMessage(methodReturn, correlationState);

                _logger.Error(msgOutputLog);

                throw;
            }
        }