From 15e562e65ced556e5979952dda85584cbdbd9e18 Mon Sep 17 00:00:00 2001
From: xiaolipro <2357729423@qq.com>
Date: Thu, 26 Feb 2026 15:04:06 +0800
Subject: [PATCH] pp
---
Directory.Build.props | 2 +-
.../InterfaceForward.Api.csproj | 14 ++-----
.../InterfaceForwardApiModule.cs | 8 +---
.../Filters/ForwardExceptionFilter.cs | 7 ++--
.../ShopeeForwardExceptionFilter.cs | 7 ++--
.../InterfaceForward.Domain.Shared.csproj | 2 +-
.../Log/Services/ILogRepository.cs | 2 +-
.../Log/Services/LogRepository.cs | 38 +++++++++----------
8 files changed, 33 insertions(+), 47 deletions(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index f5818f4..6e6a1a0 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,6 +1,6 @@
- 8.0.5.3
+ 8.0.5.6
diff --git a/src/InterfaceForward.Api/InterfaceForward.Api.csproj b/src/InterfaceForward.Api/InterfaceForward.Api.csproj
index 0773f42..880ef74 100644
--- a/src/InterfaceForward.Api/InterfaceForward.Api.csproj
+++ b/src/InterfaceForward.Api/InterfaceForward.Api.csproj
@@ -10,19 +10,11 @@
-
-
-
-
-
-
-
+
-
-
- .dockerignore
-
+
+
diff --git a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
index 9eeb619..be6e567 100644
--- a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
+++ b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
@@ -6,7 +6,7 @@ using Fake.Autofac;
using Fake.FeiShu;
using Fake.Modularity;
using Fake.Security.Claims;
-using Fake.SyncEx;
+using Fake.Serilog.Sink.FeiShu;
using InterfaceForward.Application;
using InterfaceForward.Domain.Shared;
using Microsoft.AspNetCore.Authorization;
@@ -19,6 +19,7 @@ namespace InterfaceForward.Api;
[DependsOn(typeof(FakeAuthorizationModule))]
[DependsOn(typeof(FakeAutofacModule))]
[DependsOn(typeof(InterfaceForwardApplicationModule))]
+[DependsOn(typeof(FakeSerilogSinkFeiShuModule))]
public class InterfaceForwardApiModule : FakeModule
{
private const string DefaultCorsPolicyName = "default";
@@ -123,9 +124,4 @@ public class InterfaceForwardApiModule : FakeModule
app.Services.GetRequiredService().Send("Application started");
}
-
- public override void Shutdown(ApplicationShutdownContext context)
- {
- context.ServiceProvider.GetRequiredService().Send("Application stoped");
- }
}
\ No newline at end of file
diff --git a/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs b/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs
index 78bd56d..85cfbfb 100644
--- a/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs
+++ b/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs
@@ -17,9 +17,9 @@ public class ForwardExceptionFilter(
{
private readonly InterfaceRelayOptions _options = options.Value;
- public async Task OnExceptionAsync(ExceptionContext context)
+ public Task OnExceptionAsync(ExceptionContext context)
{
- if (context.ExceptionHandled) return;
+ if (context.ExceptionHandled) return Task.CompletedTask;
/*
* ServiceProviderRequestLog设计的意义是:
@@ -50,7 +50,7 @@ public class ForwardExceptionFilter(
}
else //未处理异常
{
- await logRepository.SendFeiShuAsync(context.Exception);
+ logRepository.SendFeiShu(context.Exception);
res.Code = StatusCodes.Status500InternalServerError.ToString();
res.Msg = "服务器发生未处理异常";
context.Result = new JsonResult(res);
@@ -65,6 +65,7 @@ public class ForwardExceptionFilter(
logRepository.AppRequestLog.Response = JsonConvert.SerializeObject(res);
_ = logRepository.WriteAppLog(context.Exception);
context.ExceptionHandled = true;
+ return Task.CompletedTask;
}
private bool NeedPush(ExceptionContext context, out string subscribeName)
diff --git a/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs b/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs
index 31cc81f..817821a 100644
--- a/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs
+++ b/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs
@@ -17,9 +17,9 @@ public class ShopeeForwardExceptionFilter(
{
private readonly InterfaceRelayOptions _options = options.Value;
- public async Task OnExceptionAsync(ExceptionContext context)
+ public Task OnExceptionAsync(ExceptionContext context)
{
- if (context.ExceptionHandled) return;
+ if (context.ExceptionHandled) return Task.CompletedTask;
/*
* ServiceProviderRequestLog设计的意义是:
@@ -50,7 +50,7 @@ public class ShopeeForwardExceptionFilter(
}
else //未处理异常
{
- await logRepository.SendFeiShuAsync(context.Exception);
+ logRepository.SendFeiShu(context.Exception);
res.Code = StatusCodes.Status500InternalServerError.ToString();
res.Msg = "服务器发生未处理异常";
context.Result = new JsonResult(res);
@@ -65,6 +65,7 @@ public class ShopeeForwardExceptionFilter(
logRepository.AppRequestLog.Response = JsonConvert.SerializeObject(res);
_ = logRepository.WriteAppLog(context.Exception);
context.ExceptionHandled = true;
+ return Task.CompletedTask;
}
private bool NeedPush(ExceptionContext context, out string subscribeName)
diff --git a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj
index edc1715..11b0309 100644
--- a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj
+++ b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj
@@ -6,11 +6,11 @@
-
+
diff --git a/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs b/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs
index bb0b89c..d87fe46 100644
--- a/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs
+++ b/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs
@@ -40,7 +40,7 @@ namespace InterfaceForward.Repositories.Log.Services
/// 发飞书
///
///
- Task SendFeiShuAsync(Exception contextException);
+ void SendFeiShu(Exception contextException);
///
/// 添加日志
diff --git a/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs b/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs
index 9fd4368..425bcb5 100644
--- a/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs
+++ b/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs
@@ -1,5 +1,4 @@
-using Fake.FeiShu;
-using InterfaceForward.Domain.Shared.Dtos;
+using InterfaceForward.Domain.Shared.Dtos;
using InterfaceForward.Domain.Shared.Enum;
using InterfaceForward.Domain.Shared.Helpers;
using InterfaceForward.Repositories.Log.Entitys;
@@ -15,16 +14,13 @@ namespace InterfaceForward.Repositories.Log.Services;
///
public class LogRepository : ElasticSearchContextAbstract, ILogRepository, IScopedDependency
{
- private readonly IFeiShuNotificationService _feiShuNotificationService;
-
- public LogRepository(ConnectionFactory connection, IFeiShuNotificationService feiShuNotificationService) :
+ public LogRepository(ConnectionFactory connection) :
base(connection)
{
var guid = Guid.NewGuid();
AppRequestLog = new RequestLogDto(guid);
AppRequestLog.IsSuccess = true; // 只有接口通发生未处理异常才算应用失败
ServiceProviderRequestLog = new RequestLogDto(guid);
- _feiShuNotificationService = feiShuNotificationService;
}
public int AppId { get; set; }
@@ -44,20 +40,20 @@ public class LogRepository : ElasticSearchContextAbstract, ILogReposit
await AddLogAsync(AppRequestLog);
}
- public async Task SendFeiShuAsync(Exception contextException)
+ public void SendFeiShu(Exception contextException)
{
- await _feiShuNotificationService.SendAsync($"""
- 日志请求id:{ServiceProviderRequestLog.RequestId}
- 服务商--接口:{ServiceProviderRequestLog.Name}--{ServiceProviderRequestLog.InterfaceName}
- 异常原因:{Truncate(contextException.ToString())}
- 请求地址:{ServiceProviderRequestLog.Address}
- 原始报文:
- {Truncate(AppRequestLog.Content)}
- 请求报文:
- {Truncate(ServiceProviderRequestLog.Content)}
- 响应报文:
- {Truncate(ServiceProviderRequestLog.Response)}
- """, LogLevel.Error, CancellationToken.None);
+ Serilog.Log.Error($"""
+ 日志请求id:{ServiceProviderRequestLog.RequestId}
+ 服务商--接口:{ServiceProviderRequestLog.Name}--{ServiceProviderRequestLog.InterfaceName}
+ 异常原因:{Truncate(contextException.ToString())}
+ 请求地址:{ServiceProviderRequestLog.Address}
+ 原始报文:
+ {Truncate(AppRequestLog.Content)}
+ 请求报文:
+ {Truncate(ServiceProviderRequestLog.Content)}
+ 响应报文:
+ {Truncate(ServiceProviderRequestLog.Response)}
+ """);
}
@@ -90,11 +86,11 @@ public class LogRepository : ElasticSearchContextAbstract, ILogReposit
IndexResponse response = await Context.IndexAsync(idx,
request => request.Index($"interface_forward-{DateTime.Now:yyyy.MM.dd}"));
if (!response.IsValid)
- await _feiShuNotificationService.SendAsync("数据添加失败,原因:" + response.DebugInformation, LogLevel.Error, CancellationToken.None);
+ Serilog.Log.Error($"数据添加失败,原因:{response.DebugInformation}\n {idx.ToJson()}");
}
catch (Exception ex)
{
- await _feiShuNotificationService.SendAsync($"日志插入ES失败:{ex.Message}。{idx.ToJson()}", LogLevel.Error, CancellationToken.None);
+ Serilog.Log.Error($"日志插入ES失败:{ex.Message}。{idx.ToJson()}");
}
}