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