Explorar el Código

Merge branch 'feature/snapshot' into dev

qinchaoyue hace 4 meses
padre
commit
0f7ccc179f
Se han modificado 1 ficheros con 21 adiciones y 5 borrados
  1. 21 5
      src/Hotline/Settings/SystemLogDomain/AsyncLoggingInterceptor.cs

+ 21 - 5
src/Hotline/Settings/SystemLogDomain/AsyncLoggingInterceptor.cs

@@ -2,6 +2,7 @@
 using DotNetCore.CAP;
 using Hotline.Share.Mq;
 using Hotline.Share.Tools;
+using Microsoft.Extensions.Logging;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -15,10 +16,12 @@ public class AsyncLoggingInterceptor : AsyncInterceptorBase
 {
 
     private readonly ICapPublisher _capPublisher;
+    private readonly ILogger<AsyncLoggingInterceptor> _logger;
 
-    public AsyncLoggingInterceptor(ICapPublisher capPublisher)
+    public AsyncLoggingInterceptor(ICapPublisher capPublisher, ILogger<AsyncLoggingInterceptor> logger)
     {
         _capPublisher = capPublisher;
+        _logger = logger;
     }
 
     protected override async Task InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func<IInvocation, IInvocationProceedInfo, Task> proceed)
@@ -74,6 +77,11 @@ public class AsyncLoggingInterceptor : AsyncInterceptorBase
             if (argument == null || argument is CancellationToken) continue;
             entity.ExecuteParam = argument;
             Type argType = argument.GetType();
+            if (argument is string)
+            {
+                entity.ExternalId = argument.ToString();
+                continue;
+            }
 
             var properties = argType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
             foreach (var property in properties)
@@ -91,11 +99,19 @@ public class AsyncLoggingInterceptor : AsyncInterceptorBase
 
     private void PublishLog(SystemLog logEntity, object? result)
     {
-        if (logEntity != null)
+        try
+        {
+            if (logEntity != null)
+            {
+                logEntity.EndTime = DateTime.Now;
+                logEntity.ExecuteResult = result;
+                _capPublisher.Publish(EventNames.LoggingInterceptor, logEntity);
+            }
+
+        }
+        catch (Exception e)
         {
-            logEntity.EndTime = DateTime.Now;
-            logEntity.ExecuteResult = result;
-            _capPublisher.Publish(EventNames.LoggingInterceptor, logEntity);
+            _logger.LogError(e, "PublishLog Error");
         }
     }
 }