修改日志输出测试

IRC_NewDev
hang 2024-10-21 18:02:35 +08:00
parent 48ff2a347e
commit 823f082396
3 changed files with 10 additions and 12 deletions

View File

@ -1,4 +1,5 @@
using Serilog; using DocumentFormat.OpenXml.Bibliography;
using Serilog;
using Serilog.Events; using Serilog.Events;
using Serilog.Formatting.Compact; using Serilog.Formatting.Compact;
@ -29,11 +30,13 @@ namespace IRaCIS.Core.API
.Filter.ByExcluding(logEvent => logEvent.Properties.ContainsKey("RequestPath") && logEvent.Properties["RequestPath"].ToString().Contains("/health")) .Filter.ByExcluding(logEvent => logEvent.Properties.ContainsKey("RequestPath") && logEvent.Properties["RequestPath"].ToString().Contains("/health"))
//https://github.com/serilog/serilog-formatting-compact //https://github.com/serilog/serilog-formatting-compact
// 控制台输出 JSON 格式
.WriteTo.Console(formatter: new CompactJsonFormatter(),LogEventLevel.Warning)
// 文件输出 JSON 格式 .WriteTo.Console()
.WriteTo.File(new CompactJsonFormatter(), $"{AppContext.BaseDirectory}Serilogs/.json", rollingInterval: RollingInterval.Day); .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 和用户名 用户类型 ////控制台 方便调试 问题 我们显示记录日志 时 获取上下文的ip 和用户名 用户类型
//.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Warning, //.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Warning,

View File

@ -57,6 +57,7 @@ public class ProjectExceptionFilter(ILogger<ProjectExceptionFilter> _logger, ISt
_logger.LogError(errorInfo); _logger.LogError(errorInfo);
//_logger.LogError(exception, exception.Message);
} }
else else
{ {

View File

@ -33,12 +33,6 @@ using System.Text;
namespace IRaCIS.Core.Application.Service namespace IRaCIS.Core.Application.Service
{ {
[ApiExplorerSettings(GroupName = "Institution")] [ApiExplorerSettings(GroupName = "Institution")]
public class TestService(IRepository<Dictionary> _dicRepository, public class TestService(IRepository<Dictionary> _dicRepository,
IRepository<Trial> _trialRepository, IRepository<Trial> _trialRepository,