28 lines
1.6 KiB
C#
28 lines
1.6 KiB
C#
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();
|
|
}
|
|
}
|
|
} |