using log4net; using log4net.Config; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace common { public class LogHelper { private static ILog logger; static LogHelper() { if (logger == null) { var repository = LogManager.CreateRepository("NETCoreRepository"); //log4net从log4net.config文件中读取配置信息 XmlConfigurator.Configure(repository, new FileInfo("log4net.config")); logger = LogManager.GetLogger(repository.Name, "InfoLogger"); } } /// /// 普通日志 /// /// /// public static void Info(string message, Exception exception = null) { if (exception == null) logger.Info(message); else logger.Info(message, exception); } /// /// 告警日志 /// /// /// public static void Warn(string message, Exception exception = null) { if (exception == null) logger.Warn(message); else logger.Warn(message, exception); } /// /// 错误日志 /// /// /// public static void Error(string message, Exception exception = null) { if (exception == null) logger.Error(message); else logger.Error(message, exception); } //public static ILog log = LogManager.GetLogger(typeof(LogHelper)); //public static void Error(Exception ex) //{ // log.Error(ex); //} //public static void Error(string msg) //{ // log.Error(msg); //} //public static void Error(string msg, Exception ex) //{ // log.Error(msg, ex); //} //public static void Info(string msg) //{ // log.Info(msg); //} //public static void Debug(string msg) //{ // log.Debug(msg); //} } }