From 71509a6d431cb75ac7c97a5c913b6299cc751c36 Mon Sep 17 00:00:00 2001 From: j4587698 Date: Tue, 18 Feb 2020 17:49:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4Log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/JXCMS.Core/Log/Log.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Core/JXCMS.Core/Log/Log.cs 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