|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Serilog;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
#region << 版 本 注 释 >>
|
|
|
/*--------------------------------------------------------------------
|
|
|
* 版权所有 (c) 2026 WenJY 保留所有权利。
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
* 机器名称:T14-GEN3-7895
|
|
|
* 命名空间:Sln.Wcs.Serilog
|
|
|
* 唯一标识:8c408f49-7da2-4484-905a-c9ca16565026
|
|
|
*
|
|
|
* 创建者:WenJY
|
|
|
* 电子邮箱:
|
|
|
* 创建时间:2026-03-19 10:35:27
|
|
|
* 版本:V1.0.0
|
|
|
* 描述:
|
|
|
*
|
|
|
*--------------------------------------------------------------------
|
|
|
* 修改人:
|
|
|
* 时间:
|
|
|
* 修改说明:
|
|
|
*
|
|
|
* 版本:V1.0.0
|
|
|
*--------------------------------------------------------------------*/
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
namespace Sln.Wcs.Serilog
|
|
|
{
|
|
|
public static class SerilogExtensions
|
|
|
{
|
|
|
public static void UseSerilogExtensions(this IServiceProvider service)
|
|
|
{
|
|
|
//启用Serilog中间件
|
|
|
|
|
|
|
|
|
#region 通过配置文件读取日志存放位置
|
|
|
var configuration = service.GetService<IConfiguration>();
|
|
|
var logPath = Path.Combine(configuration["logPath"], "Logs");
|
|
|
#endregion
|
|
|
|
|
|
Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console()
|
|
|
.WriteTo.Logger(lc => lc
|
|
|
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Info"))
|
|
|
.WriteTo.File(Path.Combine($"{logPath}/Info/", "Info.log"), rollingInterval: RollingInterval.Day))
|
|
|
.WriteTo.Logger(lc => lc
|
|
|
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Plc"))
|
|
|
.WriteTo.File(Path.Combine($"{logPath}/Plc/", "Plc.log"), rollingInterval: RollingInterval.Day))
|
|
|
.WriteTo.Logger(lc => lc
|
|
|
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Agv"))
|
|
|
.WriteTo.File(Path.Combine($"{logPath}/Agv/", "Agv.log"), rollingInterval: RollingInterval.Day))
|
|
|
.WriteTo.Logger(lc => lc
|
|
|
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Rfid"))
|
|
|
.WriteTo.File(Path.Combine($"{logPath}/Rfid/", "Rfid.log"), rollingInterval: RollingInterval.Day))
|
|
|
.WriteTo.Logger(lc => lc
|
|
|
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Alarm"))
|
|
|
.WriteTo.File(Path.Combine($"{logPath}/Alarm/", "Alarm.log"), rollingInterval: RollingInterval.Day))
|
|
|
.WriteTo.Logger(lc => lc
|
|
|
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Error"))
|
|
|
.WriteTo.File(Path.Combine($"{logPath}/Error/", "Error.log"), rollingInterval: RollingInterval.Day))
|
|
|
.CreateLogger();
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|