From d0c170c2a1b57f21f6fe42547d6c4a9b44207255 Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 23 Jul 2026 13:43:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(log):=20=E4=BF=AE=E5=A4=8D=20DbUpdateExcept?= =?UTF-8?q?ion=20=E6=97=A5=E5=BF=97=E4=B8=A2=E5=A4=B1=20InnerException=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - NLog.config: exception layout 从 format=Message 改为 format=toString 原配置只渲染外层异常 Message,不递归 InnerException。DbUpdateException 外层 Message 永远是 "See the inner exception for details.",真正的 SQL 错误(主键冲突/字段超长/外键约束)全在 InnerException 里被吞掉。 改为 toString 后输出完整异常链(含 InnerException + 堆栈),全局生效。 - SwapTrade2Controller.tradeEditJson catch 块对齐其他 Controller: e.Message → e.GetBaseException().Message,并补上 e.ToJson() 数据参数, 让前端也能拿到最内层错误信息。 验证:dotnet build 0 错误 --- YLErpWeb/Controllers/SwapTrade2Controller.cs | 4 ++-- YLErpWeb/NLog.config | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/YLErpWeb/Controllers/SwapTrade2Controller.cs b/YLErpWeb/Controllers/SwapTrade2Controller.cs index 717ad13f..db1089ab 100644 --- a/YLErpWeb/Controllers/SwapTrade2Controller.cs +++ b/YLErpWeb/Controllers/SwapTrade2Controller.cs @@ -1,4 +1,4 @@ -using Autofac.Core; +using Autofac.Core; using BaseOUDAL; using CsvHelper; using DocumentFormat.OpenXml.Spreadsheet; @@ -378,7 +378,7 @@ namespace YLErp.Web.Controllers catch (Exception e) { LogFactory.GetLogger("交易保存").Error(e); - return JsonError("保存失败:" + e.Message); + return JsonError("保存失败:" + e.GetBaseException().Message, e.ToJson()); } } /// diff --git a/YLErpWeb/NLog.config b/YLErpWeb/NLog.config index 60a23827..3ab0054a 100644 --- a/YLErpWeb/NLog.config +++ b/YLErpWeb/NLog.config @@ -8,7 +8,7 @@ - +