From 823f0823962273403bc5588cfa1f423861b9d61e Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 21 Oct 2024 18:02:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_ServiceExtensions/SerilogSetup.cs | 15 +++++++++------ .../LegacyController/ProjectExceptionFilter.cs | 1 + IRaCIS.Core.Application/TestService.cs | 6 ------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/IRaCIS.Core.API/_ServiceExtensions/SerilogSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/SerilogSetup.cs index 7622f1c24..f8eb97fe1 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/SerilogSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/SerilogSetup.cs @@ -1,4 +1,5 @@ -using Serilog; +using DocumentFormat.OpenXml.Bibliography; +using Serilog; using Serilog.Events; using Serilog.Formatting.Compact; @@ -28,12 +29,14 @@ namespace IRaCIS.Core.API .Enrich.FromLogContext() .Filter.ByExcluding(logEvent => logEvent.Properties.ContainsKey("RequestPath") && logEvent.Properties["RequestPath"].ToString().Contains("/health")) - //https://github.com/serilog/serilog-formatting-compact - // 控制台输出 JSON 格式 - .WriteTo.Console(formatter: new CompactJsonFormatter(),LogEventLevel.Warning) + //https://github.com/serilog/serilog-formatting-compact - // 文件输出 JSON 格式 - .WriteTo.File(new CompactJsonFormatter(), $"{AppContext.BaseDirectory}Serilogs/.json", rollingInterval: RollingInterval.Day); + .WriteTo.Console() + .WriteTo.File($"{AppContext.BaseDirectory}Serilogs/.log", rollingInterval: RollingInterval.Day); + //// 控制台输出 JSON 格式 + //.WriteTo.Console(formatter: new CompactJsonFormatter(), LogEventLevel.Warning), + //// 文件输出 JSON 格式 + //.WriteTo.File(new CompactJsonFormatter(), $"{AppContext.BaseDirectory}Serilogs/.json", rollingInterval: RollingInterval.Day); ////控制台 方便调试 问题 我们显示记录日志 时 获取上下文的ip 和用户名 用户类型 //.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Warning, diff --git a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs index 444c1dfbd..f9fc7aa85 100644 --- a/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs +++ b/IRaCIS.Core.Application/BusinessFilter/LegacyController/ProjectExceptionFilter.cs @@ -57,6 +57,7 @@ public class ProjectExceptionFilter(ILogger _logger, ISt _logger.LogError(errorInfo); + //_logger.LogError(exception, exception.Message); } else { diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index c764d0838..61d451cb8 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -33,12 +33,6 @@ using System.Text; namespace IRaCIS.Core.Application.Service { - - - - - - [ApiExplorerSettings(GroupName = "Institution")] public class TestService(IRepository _dicRepository, IRepository _trialRepository,