@@ -22,7 +22,7 @@ public override async Task Invoke(AspectContext context, AspectDelegate next)
2222 return ;
2323 ExecuteBefore ( log , context , methodName ) ;
2424 await next ( context ) ;
25- ExecuteAfter ( log , context , methodName ) ;
25+ await ExecuteAfter ( log , context , methodName ) ;
2626 }
2727
2828 /// <summary>
@@ -45,7 +45,9 @@ public override async Task Invoke(AspectContext context, AspectDelegate next)
4545 /// <param name="methodName">方法名</param>
4646 private void ExecuteBefore ( ILog log , AspectContext context , string methodName )
4747 {
48- log . Caption ( $ "{ context . ServiceMethod . Name } 方法执行前")
48+ log
49+ . Tag ( context . ServiceMethod . Name )
50+ . Caption ( $ "{ context . ServiceMethod . Name } 方法执行前")
4951 . Class ( context . ServiceMethod . DeclaringType . FullName )
5052 . Method ( methodName ) ;
5153 foreach ( var parameter in context . GetParameters ( ) )
@@ -65,12 +67,17 @@ private void ExecuteBefore(ILog log, AspectContext context, string methodName)
6567 /// <param name="log">日志操作</param>
6668 /// <param name="context">Aspect上下文</param>
6769 /// <param name="methodName">方法名</param>
68- private void ExecuteAfter ( ILog log , AspectContext context , string methodName )
70+ private async Task ExecuteAfter ( ILog log , AspectContext context , string methodName )
6971 {
70- var parameter = context . GetReturnParameter ( ) ;
72+ if ( context . ServiceMethod . ReturnType == typeof ( Task ) ||
73+ context . ServiceMethod . ReturnType == typeof ( void ) ||
74+ context . ServiceMethod . ReturnType == typeof ( ValueTask ) )
75+ return ;
76+ var returnValue = context . IsAsync ( ) ? await context . UnwrapAsyncReturnValue ( ) : context . ReturnValue ;
77+ var returnType = returnValue . GetType ( ) . FullName ;
7178 log . Caption ( $ "{ context . ServiceMethod . Name } 方法执行后")
7279 . Method ( methodName )
73- . Content ( $ "返回类型: { parameter . ParameterInfo . ParameterType . FullName } , 返回值: { parameter . Value . SafeString ( ) } ") ;
80+ . Content ( $ "返回类型: { returnType } , 返回值: { returnValue . SafeString ( ) } ") ;
7481 WriteLog ( log ) ;
7582 }
7683 }
0 commit comments