From 2aef482fa7431fb47eef94081ff23ec220f89820 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期五, 24 一月 2025 09:10:31 +0800
Subject: [PATCH] 1

---
 WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs |   55 ++++++++-----------------------------------------------
 1 files changed, 8 insertions(+), 47 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs
index 6b22f40..b335d72 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs
@@ -16,7 +16,7 @@
 namespace WIDESEAWCS_Core.AOP
 {
     /// <summary>
-	/// 鎷︽埅鍣˙logLogAOP 缁ф壙IInterceptor鎺ュ彛
+	/// 鎷︽埅鍣↙ogAOP 缁ф壙IInterceptor鎺ュ彛
 	/// </summary>
 	public class LogAOP : IInterceptor
     {
@@ -26,7 +26,6 @@
         {
             _accessor = accessor;
         }
-
 
         /// <summary>
         /// 瀹炰緥鍖朓Interceptor鍞竴鏂规硶 
@@ -38,7 +37,7 @@
             string json;
             try
             {
-                if(invocation.Arguments.Any())
+                if (invocation.Arguments.Any())
                 {
                     json = JsonConvert.SerializeObject(invocation.Arguments);
                 }
@@ -73,9 +72,6 @@
                 // 寮傛鑾峰彇寮傚父锛屽厛鎵ц
                 if (IsAsyncMethod(invocation.Method))
                 {
-                    #region 鏂规涓�
-
-                    //Wait task execution and modify return value
                     if (invocation.Method.ReturnType == typeof(Task))
                     {
                         invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(
@@ -86,45 +82,17 @@
                                 LogEx(ex, apiLogAopInfo);
                             });
                     }
-                    //Task<TResult>
                     else
                     {
                         invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult(
                             invocation.Method.ReturnType.GenericTypeArguments[0],
                             invocation.ReturnValue,
-                            //async () => await SuccessAction(invocation, dataIntercept),/*鎴愬姛鏃舵墽琛�*/
                             async (o) => await SuccessAction(invocation, apiLogAopInfo, startTime, o), /*鎴愬姛鏃舵墽琛�*/
                             ex =>
                             {
                                 LogEx(ex, apiLogAopInfo);
                             });
                     }
-
-                    #endregion
-
-
-                    // 濡傛灉鏂规涓�涓嶈锛岃瘯璇曡繖涓柟妗�
-                    //#region 鏂规浜�
-
-                    //var type = invocation.Method.ReturnType;
-                    //var resultProperty = type.GetProperty("Result");
-                    //DateTime endTime = DateTime.Now;
-                    //string ResponseTime = (endTime - startTime).Milliseconds.ToString();
-                    //apiLogAopInfo.ResponseTime = endTime.ToString("yyyy-MM-dd hh:mm:ss fff");
-                    //apiLogAopInfo.ResponseIntervalTime = ResponseTime + "ms";
-                    //apiLogAopInfo.ResponseJsonData = JsonConvert.SerializeObject(resultProperty.GetValue(invocation.ReturnValue));
-
-                    ////dataIntercept += ($"銆愬搷搴旀椂闂淬�戯細{ResponseTime}ms\r\n");
-                    ////dataIntercept += ($"銆愭墽琛屽畬鎴愭椂闂淬�戯細{endTime.ToString("yyyy-MM-dd hh:mm:ss fff")}\r\n");
-                    ////dataIntercept += ($"銆愭墽琛屽畬鎴愮粨鏋溿�戯細{JsonConvert.SerializeObject(resultProperty.GetValue(invocation.ReturnValue))}\r\n");
-
-                    //Parallel.For(0, 1, e =>
-                    //{
-                    //    //LogLock.OutLogAOP("AOPLog", new string[] { dataIntercept });
-                    //    LogLock.OutLogAOP("AOPLog", new string[] { apiLogAopInfo.GetType().ToString() + " - ResponseJsonDataType:" + type, JsonConvert.SerializeObject(apiLogAopInfo) });
-                    //});
-
-                    //#endregion
                 }
                 else
                 {
@@ -148,16 +116,14 @@
                     apiLogAopInfo.ResponseJsonData = jsonResult;
                     Parallel.For(0, 1, e =>
                     {
-                        LogLock.OutLogAOP("AOPLog", new string[] { apiLogAopInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopInfo) });
+                        LogLock.OutLogAOP("鍏ㄥ眬鏃ュ織AOP", new string[] { apiLogAopInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopInfo) });
                     });
                 }
             }
             catch (Exception ex) // 鍚屾2
             {
                 LogEx(ex, apiLogAopInfo);
-                throw;
             }
-
         }
 
         private async Task SuccessAction(IInvocation invocation, AOPLogInfo apiLogAopInfo, DateTime startTime, object o = null)
@@ -168,13 +134,11 @@
             apiLogAopInfo.ResponseIntervalTime = ResponseTime + "ms";
             apiLogAopInfo.ResponseJsonData = JsonConvert.SerializeObject(o);
 
-
             await Task.Run(() =>
             {
                 Parallel.For(0, 1, e =>
                 {
-                    //LogLock.OutSql2Log("AOPLog", new string[] { JsonConvert.SerializeObject(apiLogAopInfo) });
-                    LogLock.OutLogAOP("AOPLog", new string[] { apiLogAopInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopInfo) });
+                    LogLock.OutLogAOP("鍏ㄥ眬鏃ュ織AOP", new string[] { apiLogAopInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopInfo) });
                 });
             });
         }
@@ -196,7 +160,7 @@
                 // 寮傚父鏃ュ織閲屾湁璇︾粏鐨勫爢鏍堜俊鎭�
                 Parallel.For(0, 1, e =>
                 {
-                    LogLock.OutLogAOP("AOPLogEx", new string[] { apiLogAopExInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopExInfo) });
+                    LogLock.OutLogAOP("鍏ㄥ眬寮傚父閿欒鏃ュ織AOP", new string[] { apiLogAopExInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopExInfo) });
                 });
             }
         }
@@ -204,10 +168,7 @@
 
         public static bool IsAsyncMethod(MethodInfo method)
         {
-            return
-                method.ReturnType == typeof(Task) ||
-                method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)
-            ;
+            return method.ReturnType == typeof(Task) || method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>);
         }
     }
 
@@ -258,7 +219,7 @@
             Func<object, Task> action, Action<Exception> finalAction)
         {
             return typeof(InternalAsyncHelper)
-                .GetMethod("AwaitTaskWithPostActionAndFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static)
+                .GetMethod(nameof(AwaitTaskWithPostActionAndFinallyAndGetResult), BindingFlags.Public | BindingFlags.Static)
                 .MakeGenericMethod(taskReturnType)
                 .Invoke(null, new object[] { actualReturnValue, action, finalAction });
         }
@@ -289,7 +250,7 @@
         /// <summary>
         /// 璇锋眰鍙傛暟鏁版嵁JSON
         /// </summary>
-        [Description("璇锋眰鍙傛暟鏁版嵁JSON")] 
+        [Description("璇锋眰鍙傛暟鏁版嵁JSON")]
         public string RequestParamsData { get; set; } = string.Empty;
         /// <summary>
         /// 璇锋眰鍝嶅簲闂撮殧鏃堕棿

--
Gitblit v1.9.3