using HighWayIot.Repository.service;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HighWayIot.Log4net;

namespace HighWayIot.Winform.Business
{
    public class SqlLogHelper
    {
        private static LogHelper logHelper = LogHelper.Instance;

        /// <summary>
        /// 日志信息服务类
        /// </summary>
        private static SysLogService sysLogService = SysLogService.Instance;

        /// <summary>
        /// 报警日志信息服务类
        /// </summary>
        private static SysErrorLogService sysErrorLogService = SysErrorLogService.Instance;

        /// <summary>
        /// 日志插入数据库
        /// </summary>
        public static void AddLog(string text, int? p1 = null, int? p2 = null, int? p3 = null)
        {
            logHelper.Info(text);
            sysLogService.InsertLogInfo(new SysLogEntity()
            {
                Text = text,
                LogTime = DateTime.Now,
                Operator = RoleBusiness.LoginUserName,
                P1 = p1,
                P2 = p2,
                P3 = p3,
            });
        }

        /// <summary>
        /// 错误日志插入数据库
        /// </summary>
        public static void AddErrorLog(string text, int? p1 = null, int? p2 = null, int? p3 = null)
        {
            logHelper.Error(text);
            sysErrorLogService.InsertErrorLogInfo(new SysErrorLogEntity()
            {
                Text = text,
                LogTime = DateTime.Now,
                Operator = RoleBusiness.LoginUserName,
                P1 = p1,
                P2 = p2,
                P3 = p3,
            });
        }
    }
}
