60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
|
using Serilog;
|
||
|
using Serilog.Core;
|
||
|
using Serilog.Events;
|
||
|
|
||
|
namespace MasstransferCommon.Config;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 日志配置类
|
||
|
/// </summary>
|
||
|
public class LogConfiguration
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 获取日志配置对象
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public static Logger GetLogger()
|
||
|
{
|
||
|
// 日志输出目录
|
||
|
var basePath = AppDomain.CurrentDomain.BaseDirectory;
|
||
|
|
||
|
return new LoggerConfiguration()
|
||
|
.MinimumLevel.Debug()
|
||
|
.Enrich.FromLogContext()
|
||
|
.WriteTo.Logger(
|
||
|
l =>
|
||
|
l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Debug)
|
||
|
.WriteTo.File(
|
||
|
Path.Combine(basePath, "logs", "debug", "debug-.log"),
|
||
|
rollingInterval: RollingInterval.Hour,
|
||
|
retainedFileCountLimit: 24
|
||
|
)
|
||
|
)
|
||
|
.WriteTo.Logger(
|
||
|
l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information)
|
||
|
.WriteTo.File(
|
||
|
Path.Combine(basePath, "logs", "info", "info-.log"),
|
||
|
rollingInterval: RollingInterval.Hour,
|
||
|
retainedFileCountLimit: 72
|
||
|
)
|
||
|
)
|
||
|
.WriteTo.Logger(
|
||
|
l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning)
|
||
|
.WriteTo.File(
|
||
|
Path.Combine(basePath, "logs", "warning", "warning-.log"),
|
||
|
rollingInterval: RollingInterval.Day,
|
||
|
retainedFileCountLimit: 30
|
||
|
)
|
||
|
)
|
||
|
.WriteTo.Logger(
|
||
|
l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error)
|
||
|
.WriteTo.File(
|
||
|
Path.Combine(basePath, "logs", "error", "error-.log"),
|
||
|
rollingInterval: RollingInterval.Day,
|
||
|
retainedFileCountLimit: 90
|
||
|
)
|
||
|
)
|
||
|
.WriteTo.Console()
|
||
|
.CreateLogger();
|
||
|
}
|
||
|
}
|