提交Log

This commit is contained in:
j4587698 2020-02-18 17:49:38 +08:00
parent c448afdd1d
commit 71509a6d43

View File

@ -0,0 +1,28 @@
using System.IO;
using JXCMS.Core.Utils;
using Serilog;
using Serilog.Events;
namespace JXCMS.Core.Log
{
public class Log
{
public static void Init()
{
if (!Directory.Exists(@"Logs"))
{
Directory.CreateDirectory(@"Logs");
}
Serilog.Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(ConfigHelper.Configs)
.WriteTo.Console()
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information && !e.Properties.ContainsKey("name")).WriteTo.RollingFile(@"Logs\Info-{Date}.log"))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Debug && !e.Properties.ContainsKey("name") ).WriteTo.RollingFile(@"Logs\Debug-{Date}.log"))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning && !e.Properties.ContainsKey("name") ).WriteTo.RollingFile(@"Logs\Warning-{Date}.log"))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error && !e.Properties.ContainsKey("name") ).WriteTo.RollingFile(@"Logs\Error-{Date}.log"))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Fatal && !e.Properties.ContainsKey("name") ).WriteTo.RollingFile(@"Logs\Fatal-{Date}.log"))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Properties.ContainsKey("name") ).WriteTo.RollingFile(@"Logs\Spider-{Date}.log"))
.CreateLogger();
}
}
}