#region << 版 本 注 释 >>

/*--------------------------------------------------------------------
* 版权所有 (c) 2026 WenJY 保留所有权利。
* CLR版本：4.0.30319.42000
* 机器名称：Mr.Wen's MacBook Pro
* 命名空间：Sln.IntelliBelt.Serilog
* 唯一标识：957B0826-B1A6-4BBB-9E74-C2584DF5023A
*
* 创建者：WenJY
* 电子邮箱：
* 创建时间：2026-04-24 14:56:32
* 版本：V1.0.0
* 描述：
*
*--------------------------------------------------------------------
* 修改人：
* 时间：
* 修改说明：
*
* 版本：V1.0.0
*--------------------------------------------------------------------*/

#endregion << 版 本 注 释 >>

using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Sln.IntelliBelt.Config;

namespace Sln.IntelliBelt.Serilog;

public static class SerilogExtensions
{
    public static void  UseSerilogExtensions(this IServiceProvider service)
    {
        //启用Serilog中间件
            

        #region 通过配置文件读取日志存放位置
        var appConfig = service.GetService<AppConfig>();
        var logPath = Path.Combine(appConfig.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("Iot"))
                .WriteTo.File(Path.Combine($"{logPath}/Iot/", "Iot.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();

    }
}