| | |
| | | /// <returns></returns> |
| | | public static IServiceCollection AddConfigSerilog(this IServiceCollection services) |
| | | { |
| | | // 创建Serilog记录日志 |
| | | //Log.Logger = new LoggerConfiguration() |
| | | // .MinimumLevel.Debug() |
| | | // .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) |
| | | // .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Fatal) |
| | | // .MinimumLevel.Override("Quartz", LogEventLevel.Warning) |
| | | // .MinimumLevel.Override("Serilog", LogEventLevel.Information) |
| | | // // 全部日志写入到Console |
| | | // .WriteTo.Console() |
| | | // .WriteTo.Async(c => c.Console( |
| | | // theme: AnsiConsoleTheme.Literate, |
| | | // outputTemplate: template)) |
| | | // // Debug日志写入到文件 |
| | | // .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Debug)) |
| | | // .WriteTo.Async(c => c.File( |
| | | // path: "Logs/Debug_.txt", |
| | | // rollingInterval: RollingInterval.Day, |
| | | // fileSizeLimitBytes: 1024 * 1024 * 10, |
| | | // retainedFileCountLimit: 100, |
| | | // outputTemplate: template, |
| | | // restrictedToMinimumLevel: LogEventLevel.Debug)) |
| | | // // Information日志写入到文件 |
| | | // .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Information)) |
| | | // .WriteTo.Async(c => c.File( |
| | | // path: "Logs/Information_.txt", |
| | | // rollingInterval: RollingInterval.Day, |
| | | // fileSizeLimitBytes: 1024 * 1024 * 10, |
| | | // retainedFileCountLimit: 100, |
| | | // outputTemplate: template, |
| | | // restrictedToMinimumLevel: LogEventLevel.Information)) |
| | | // // Warning日志写入到文件 |
| | | // .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Warning)) |
| | | // .WriteTo.Async(c => c.File( |
| | | // path: "Logs/Warning_.txt", |
| | | // rollingInterval: RollingInterval.Day, |
| | | // fileSizeLimitBytes: 1024 * 1024 * 10, |
| | | // retainedFileCountLimit: 100, |
| | | // outputTemplate: template, |
| | | // restrictedToMinimumLevel: LogEventLevel.Warning)) |
| | | // // Error日志写入到文件 |
| | | // .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Error)) |
| | | // .WriteTo.Async(c => c.File( |
| | | // path: "Logs/Error_.txt", |
| | | // rollingInterval: RollingInterval.Day, |
| | | // fileSizeLimitBytes: 1024 * 1024 * 10, |
| | | // retainedFileCountLimit: 1000, |
| | | // outputTemplate: template, |
| | | // restrictedToMinimumLevel: LogEventLevel.Error)) |
| | | // .CreateLogger(); |
| | | |
| | | //Log.Logger = new LoggerConfiguration() |
| | | // .Enrich.FromLogContext() |
| | | // .WriteTo.Console() // 输出到控制台 |
| | | // .MinimumLevel.Debug() // 测试最小记录级别 |
| | | // .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => { |
| | | // var result = p.Properties.FirstOrDefault(c => c.Key == "SourceContext").Value; |
| | | // if (result != null) |
| | | // { |
| | | // return result.ToString().Contains("模块名"); |
| | | // } |
| | | // return false; |
| | | // }).WriteTo |
| | | // .File(LogFilePath("模块目录"), rollingInterval: RollingInterval.Day, outputTemplate: template)) |
| | | // .CreateLogger(); |
| | | Log.Logger = new LoggerConfiguration() |
| | | .MinimumLevel.Debug() |
| | | .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) |
| | |
| | | .WriteTo.Async(c => c.Console( |
| | | theme: AnsiConsoleTheme.Literate, |
| | | outputTemplate: template)) |
| | | // Debug日志写入到文件 |
| | | //.WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Debug)) |
| | | //.WriteTo.Async(c => c.File( |
| | | // path: "Logs/Debug_.txt", |
| | | // rollingInterval: RollingInterval.Day, |
| | | // fileSizeLimitBytes: 1024 * 1024 * 10, |
| | | // retainedFileCountLimit: 100, |
| | | // outputTemplate: template, |
| | | // restrictedToMinimumLevel: LogEventLevel.Debug)) |
| | | .WriteTo.Logger(lc => lc |
| | | .Filter.ByIncludingOnly((e) => e.Level == Serilog.Events.LogEventLevel.Information) |
| | | .WriteTo.File("Logs/info/.log", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 10)) |