解决 net7 core Serilog 日志无法生成问题
解决 net7 core Serilog 日志无法生成问题
net7的日志组件配置代码:
var builder = WebApplication.CreateBuilder(args); builder.Host.UseSerilog(dispose: true); // Add services to the container. builder.Services.AddControllersWithViews(); Log.Logger = new LoggerConfiguration() //错误信息 .MinimumLevel.Error() .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Error) .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Error) //警告信息 .MinimumLevel.Warning() .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Warning) .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning) //调试信息 .MinimumLevel.Debug() .WriteTo.File(Path.Combine("Log", "log.txt"), rollingInterval: RollingInterval.Day) .CreateLogger();