1234567891011121314151617181920212223242526272829303132333435363738394041 |
- // <author></author>
- // <date></date>
- // <description></description>
- using ERP.Framework.Config;
- using Serilog;
- namespace ERP.Framework.Logger
- {
- public static class LoggerBuilder
- {
- public static ILogger CreateLogger(LogConfig logConfig)
- {
- // 扩展增加Elk 或 MongoDB等
- //if (logConfig.LogType == Enum.LogTypeEnum.Els)
- //{
- // return ...
- //}
- return AddLocalLog(logConfig);
- }
- private static ILogger AddLocalLog(LogConfig logConfig)
- {
- var outputTemplete = "[{Timestep:yyyy-MM-dd HH:mm:ss.fff}] {Level} ({SourceContext}) {Message} {NewLine} {Exception}";
- var logConfiguration = new LoggerConfiguration()
- .MinimumLevel.Debug()
- .WriteTo.File(logConfig.FilePath,
- rollingInterval: RollingInterval.Day,// 文件类别(分支,小时,天)
- outputTemplate: outputTemplete, // 日志模板
- retainedFileCountLimit: 31, // 日志文件最大个数
- retainedFileTimeLimit: TimeSpan.FromDays(7), // 日志保存时间
- rollOnFileSizeLimit: true, // 是否限制单个文件最大大小
- fileSizeLimitBytes: 52428800 // 单个文件最大大小
- );
- return logConfiguration.CreateLogger();
- }
- }
- }
|