using Nirvana.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace YBDevice.Api.DBServices
{
    /// <summary>
    /// 日志处理
    /// </summary>
    public partial class LoggerApp
    {
        /// <summary>
        /// 记录文本日志
        /// </summary>ye m
        /// <param name="param">参数</param>
        /// <param name="ex">异常</param>
        /// <param name="type">类型</param>
        /// <param name="program">程序名称</param>
        public void InsertErrorLog(Exception ex, string param = "", string program = "", int type = 1)
        {
            var msg = $"ex:{ex.Message},source:{ex.Source}\r\nstack:{ex.StackTrace}";
            if (ex.InnerException != null)
            {
                msg = $"{msg}\r\nInnerException.Message:{ex.InnerException.Message},InnerException.Source:{ex.InnerException.Source}\r\nInnerException.StackTrace:{ex.InnerException.StackTrace}";
            }
            if (!string.IsNullOrEmpty(param))
            {
                msg = $"参数:{param}\r\n{msg}";
            }
            if (!string.IsNullOrEmpty(program))
            {
                msg = $"{program}:{msg}";
            }
            InsertErrorLog(msg, type);
        }
        /// <summary>
        /// 插入日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="type"></param>
        public void InsertErrorLog(string msg, int type = 1)
        {
            LogFactory.InsertErrorLog(msg, type);
        }
    }
}
