AOP如何在业务结束时,根据参入参数和返回结果添加日志

IMethodReturn retvalue = getNext()(input, getNext);

            if (retvalue.Exception != null)
            {
                System.IO.File.AppendAllText("a.txt", retvalue.Exception.ToString());
                retvalue.Exception = null;
            }

            if (retvalue != null)
            {
                var dll = Assembly.Load("AopIntercept");
                Type tx = dll.GetType("AopIntercept."+input.Target.ToString().Substring(input.Target.ToString().LastIndexOf(".") + 1) + "Log");
                MethodInfo mf = tx.GetMethod("Log");
                List<object> list = new List<object>();
                 list.Add(retvalue.ReturnValue);

                 foreach (var item in input.Inputs)
                 {
                     list.Add(item);
                 }
               

                mf.Invoke(null, list.ToArray());

              
            }
            return retvalue;

 

posted @ 2016-08-10 11:36  haiziguo  阅读(1251)  评论(0编辑  收藏  举报