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); } /// /// Error /// /// /// 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); } } /// /// Info /// /// /// 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); } } /// /// Debug /// /// /// 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); } } /// /// Warn /// /// /// 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); } } } }