diff --git a/Core/JXCMS.Core/Log/Log.cs b/Core/JXCMS.Core/Log/Log.cs new file mode 100644 index 0000000..a34dede --- /dev/null +++ b/Core/JXCMS.Core/Log/Log.cs @@ -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(); + } + } +} \ No newline at end of file