通过 RollingFile
方法的 retainedFileCountLimit
参数设置
public static IWebHostBuilder BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog((ctx, conf) =>
{
conf.ReadFrom.Configuration(ctx.Configuration)
.WriteTo.RollingFile(Path.GetFullPath("logs/log-{Date}.log"), retainedFileCountLimit: 7);
});
}