using System.Diagnostics;
using log4net;
using System.Reflection;

namespace GcDevicePc.Common
{
    public static class Log
    {
        private static readonly ILog logInfo = LogManager.GetLogger("Log");
        private static readonly ILog hmiInfo = LogManager.GetLogger("HmiInfo");
        private static readonly ILog logErr = LogManager.GetLogger("Err");

        /// <summary>
        /// 记录正常的消息
        /// </summary>
        /// <param name="msg">消息内容</param>
        public static void Info(string msg)
        {
            logInfo.Info(msg);
        }

        /// <summary>
        /// 记录HMI的消息
        /// </summary>
        /// <param name="msg">消息内容</param>
        public static void HmiInfo(string msg)
        {
            hmiInfo.Info(msg);
        }

        /// <summary>
        /// 记录异常信息
        /// </summary>
        /// <param name="msg">异常信息内容</param>
        public static void Error(string msg)
        {
            StackTrace stackTrace = new StackTrace();
            StackFrame stackFrame = stackTrace.GetFrame(1);
            MethodBase methodBase = stackFrame.GetMethod();
            logErr.Error("ClassName:" + methodBase.ReflectedType.Name + " Func Name:" + methodBase.Name + " Info:" + msg);
        }
    }
}
