using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace RMYY_CallCenter_Api.Utility
{
    public class LogHelper
    {

        static LogHelper()
        {
            FileInfo configFile = new FileInfo(HttpContext.Current.Server.MapPath("/Configs/log4net.config"));
            log4net.Config.XmlConfigurator.Configure(configFile);
        }
        /// <summary>
        /// Error
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void Error(string message, Exception ex = null)
        {
            ILog _log = LogManager.GetLogger(new StackTrace().GetFrame(1).GetMethod().DeclaringType.FullName);
            if (ex != null)
            {
                _log.Error(message, ex);
            }
            else
            {
                _log.Error(message);
            }
        }
        /// <summary>
        /// Info
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void Info(string message, Exception ex = null)
        {
            ILog _log = LogManager.GetLogger(new StackTrace().GetFrame(1).GetMethod().DeclaringType.FullName);
            if (ex != null)
            {
                _log.Info(message, ex);
            }
            else
            {
                _log.Info(message);
            }
        }
        /// <summary>
        /// Debug
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void Debug(string message, Exception ex = null)
        {
            ILog _log = LogManager.GetLogger(new StackTrace().GetFrame(1).GetMethod().DeclaringType.FullName);
            if (ex != null)
            {
                _log.Debug(message, ex);
            }
            else
            {
                _log.Debug(message);
            }
        }
        /// <summary>
        /// Warn
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void Warn(string message, Exception ex = null)
        {
            ILog _log = LogManager.GetLogger(new StackTrace().GetFrame(1).GetMethod().DeclaringType.FullName);
            if (ex != null)
            {
                _log.Warn(message, ex);
            }
            else
            {
                _log.Warn(message);
            }
        }
    }
}
