using log4net;
using log4net.Config;
using System;
using System.Diagnostics;
using System.IO;


namespace AIRS
{
    /// <summary>
    /// function：Log
    /// author  ：lbf
    /// date    ：2020/6/17 17:31:13 
    /// </summary>
    /// <summary>

    /// 使用Log4net插件的log日志对象

    /// </summary>

    public static class Log

    {

        private static ILog log;


        
        static Log()

        {

            XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));

            log = LogManager.GetLogger(typeof(Log));

        }
        private static string getTraceMessage(object message)
        {
            var traceInfo = new StackTrace();
            return string.Format("[{0}-{1}] {2}", traceInfo.GetFrame(2).GetMethod().ReflectedType.Name, traceInfo.GetFrame(2).GetMethod().Name, message);
        }


        public static void Debug(object message)

        {

            log.Debug(getTraceMessage( message));

        }



        public static void DebugFormatted(string format, params object[] args)

        {

            log.DebugFormat(format, args);

        }



        public static void Info(object message)

        {

            log.Info(getTraceMessage(message));

        }



        public static void InfoFormatted(string format, params object[] args)

        {

            log.InfoFormat(format, args);

        }



        public static void Warn(object message)

        {

            log.Warn(getTraceMessage(message));

        }



        public static void Warn(object message, Exception exception)

        {

            log.Warn(getTraceMessage(message), exception);

        }



        public static void WarnFormatted(string format, params object[] args)

        {

            log.WarnFormat(format, args);

        }



        public static void Error(object message)

        {

            log.Error(getTraceMessage(message));

        }



        public static void Error(object message, Exception exception)

        {

            log.Error(message, exception);

        }



        public static void ErrorFormatted(string format, params object[] args)

        {

            log.ErrorFormat(format, args);

        }



        public static void Fatal(object message)

        {

            log.Fatal(getTraceMessage(message));

        }



        public static void Fatal(object message, Exception exception)

        {

            log.Fatal(getTraceMessage(message), exception);

        }



        public static void FatalFormatted(string format, params object[] args)

        {

            log.FatalFormat(format, args);

        }

    }
}
