using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using log4net; using System.IO; namespace Logs { public class LogHelper { static LogHelper() { string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\logconfig.xml"; log4net.Config.XmlConfigurator.Configure(new FileInfo(path)); } /// /// 接口 /// private static ILog __GetLog(Object obj) { string name = string.Empty; if (obj.GetType().Name == "String") { name = obj.ToString(); } else { name = obj.GetType().Name; } return log4net.LogManager.GetLogger(name); } /// /// 调试 /// /// 消息 public static void Debug(string message) { ILog log = __GetLog(string.Empty); if (log.IsDebugEnabled) log.Debug(message); } public static void Debug(Object obj, string message) { ILog log = __GetLog(obj); if (log.IsDebugEnabled) __GetLog(obj).Debug(message); } /// /// 调试 /// /// 消息 /// 异常 public static void Debug(string message, Exception ex) { ILog log = __GetLog(string.Empty); if (log.IsDebugEnabled) log.Debug(message, ex); } public static void Debug(Object obj, string message, Exception ex) { ILog log = __GetLog(obj); if (log.IsDebugEnabled) __GetLog(obj).Debug(message, ex); } /// /// 信息 /// /// 消息 public static void Info(string message) { ILog log = __GetLog(string.Empty); if (log.IsInfoEnabled) log.Info(message); } /// /// 信息 /// /// 消息 /// 异常 public static void Info(string message, Exception ex) { ILog log = __GetLog(string.Empty); if (log.IsInfoEnabled) log.Info(message, ex); } /// /// 一般错误 /// /// 消息 public static void Error(string message) { ILog log = __GetLog(string.Empty); if (log.IsErrorEnabled) log.Error(message); } /// /// 一般错误 /// /// 消息 /// 异常 public static void Error(string message, Exception exception) { ILog log = __GetLog(string.Empty); if (log.IsErrorEnabled) log.Error(message, exception); } /// /// 警告 /// /// 消息 public static void Warn(string message) { ILog log = __GetLog(string.Empty); if (log.IsWarnEnabled) log.Warn(message); } /// /// 警告 /// /// 消息 /// 异常 public static void Warn(string message, Exception ex) { ILog log = __GetLog(string.Empty); if (log.IsWarnEnabled) log.Warn(message, ex); } /// /// 严重 /// /// 消息 public static void Fatal(string message) { ILog log = __GetLog(string.Empty); if (log.IsFatalEnabled) log.Fatal(message); } /// /// 严重 /// /// 消息 /// 异常 public static void Fatal(string message, Exception ex) { ILog log = __GetLog(string.Empty); if (log.IsFatalEnabled) log.Fatal(message, ex); } } }