上一节介绍了如何在abp项目中使用LogDashboard,接着本小节介绍项目中如何输出日志,并在LogDashboard 日志面板中查看。
- Log.Logger = new LoggerConfiguration()
- #if DEBUG
- .MinimumLevel.Debug()
- #else
- .MinimumLevel.Information()
- #endif
- .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
- .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
- .Enrich.FromLogContext() //记录相关上下文信息
- //restrictedToMinimumLevel 最小记录级别
- //rollingInterval 滚动方式,按小时记录,根据个人要求调整
- // File 输出到本地
- .WriteTo.Async(c => c.File("Logs/logs.log", outputTemplate: "{Timestamp:HH:mm} || {Level} || {SourceContext:l} || {Message} || {Exception} ||end {NewLine}", rollingInterval:RollingInterval.Hour,restrictedToMinimumLevel: LogEventLevel.Information))
- .WriteTo.Logger(log =>
- log.Filter.ByIncludingOnly(evt => evt.Level == LogEventLevel.Fatal)
- .WriteTo.File(
- $"Logs/{(DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) + "-Fatal.log")}",
- fileSizeLimitBytes: 83886080),
- LogEventLevel.Fatal)
- .WriteTo.Logger(log =>
- log.Filter.ByIncludingOnly(evt => evt.Level == LogEventLevel.Error)
- .WriteTo.File(
- $"Logs/{(DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) + "-Error.log")}",
- fileSizeLimitBytes: 83886080),
- LogEventLevel.Fatal)
- //.WriteTo.Console() // 打印输出到控制台
- #if DEBUG
- .WriteTo.Async(c => c.Console())
- #endif
- .CreateLogger();

_ILogger.LogInformation

根据需求使用,有很多种输出方式。


其他就自己慢慢研究了,日志管理功能至此结束。