From 70233af5426b0d1c343ebe87183303a34a9aaa58 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期三, 20 十一月 2024 09:05:38 +0800 Subject: [PATCH] WIDESEAWCS_QuartzJob更新版本 --- WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs | 49 +++++-------------------------------------------- 1 files changed, 5 insertions(+), 44 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs index 6b22f40..f963e82 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 { @@ -155,9 +123,7 @@ catch (Exception ex) // 鍚屾2 { LogEx(ex, apiLogAopInfo); - throw; } - } private async Task SuccessAction(IInvocation invocation, AOPLogInfo apiLogAopInfo, DateTime startTime, object o = null) @@ -168,12 +134,10 @@ 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) }); }); }); @@ -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