public void Intercept(IInvocation invocation)
        {
            if (!isMatch(invocation.Method))
            {
                invocation.Proceed();
                return;
            }

            MethodExcuteTraceInfo traceInfo = new MethodExcuteTraceInfo();

            traceInfo.CallDt        = DateTime.Now;
            traceInfo.ServiceName   = invocation.MethodInvocationTarget?.DeclaringType.Name;
            traceInfo.InterfaceName = invocation.Method.DeclaringType.Name;
            traceInfo.MethodName    = invocation.Method.Name;
            if (invocation.Arguments != null && invocation.Arguments.Any())
            {
                //过滤掉接口
                //Dictionary<string, object> parameters = new Dictionary<string, object>();

                traceInfo.ParameterInfo = JsonConvert.SerializeObject(invocation.Arguments);
            }

            try
            {
                invocation.Proceed();
            }
            catch (Exception e)
            {
                traceInfo.IsError         = true;
                traceInfo.ErrorMessage    = e.Message;
                traceInfo.ErrorStackTrace = e.StackTrace;

                throw;
            }
            finally
            {
                traceInfo.CompleteDt = DateTime.Now;
                if (!traceInfo.IsError && invocation.ReturnValue != null)
                {
                    traceInfo.ResultData = JsonConvert.SerializeObject(invocation.ReturnValue);
                }

                if (_methodExcuteTraceRepository != null)
                {
                    _methodExcuteTraceRepository.SaveMethodExcuteTraceInfo(traceInfo);
                }
            }
        }
        public bool PreProceed(Aop.AspectContext aspectContext)
        {
            if (!isMatch(aspectContext.Method.Method))
            {
                return(true);
            }

            excuteTraceInfo = new MethodExcuteTraceInfo();

            excuteTraceInfo.CallDt = DateTime.Now;
            //excuteTraceInfo.ServiceName = invocation.MethodInvocationTarget?.DeclaringType.Name;
            excuteTraceInfo.InterfaceName = aspectContext.Method.Method.DeclaringType.Name;
            excuteTraceInfo.MethodName    = aspectContext.Method.Method.Name;
            if (aspectContext.Method.Parameters != null && aspectContext.Method.Parameters.Any())
            {
                excuteTraceInfo.ParameterInfo = JsonConvert.SerializeObject(aspectContext.Method.Parameters);
            }

            return(true);
        }
Exemplo n.º 3
0
 public void SaveMethodExcuteTraceInfo(MethodExcuteTraceInfo traceInfo)
 {
     _logger.LogInformation(JsonConvert.SerializeObject(traceInfo));
 }
Exemplo n.º 4
0
 public void SaveMethodExcuteTraceInfo(MethodExcuteTraceInfo traceInfo)
 {
     Debug.WriteLine(JsonConvert.SerializeObject(traceInfo));
 }