using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace athosRT.tool { public static class LogObject { private static List LogList = new List(); private static int LogNum = 100; public static log4net.ILog Log(string LoggerName) { //log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); return log4net.LogManager.GetLogger(LoggerName); } public static void Info(string classname, string msg) { Log(classname).Info(msg); UpdataLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")} \t INFO \t{classname} \t {msg}"); } public static void Info(string classname, string Device, string msg) { Log(classname).Info(Device + ":\t" + msg); } public static void Debug(string classname, string msg, Exception ex) { Log(classname).Debug(msg, ex); } public static void Error(string classname, Exception ex) { Log(classname).Error(ex); UpdataLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")} \t ERROR \t {classname} \t {ex}"); } public static void Error(string classname, string msg, Exception ex) { Log(classname).Error(msg, ex); UpdataLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")} \t ERROR \t {classname} \t {ex}"); } public static void Warning(string Device, string msg) { Log(Device).Warn(Device + ":\t" + msg); UpdataLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")} \t WARNING \t {Device} \t {msg}"); } public static void Warning(string classname, string Device, string msg) { Log(classname).Warn(Device + ":\t" + msg); UpdataLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")} \t WARNING \t {Device} \t {msg}"); } public static void Error(string classname, string msg) { Log(classname).Error(msg); UpdataLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")} \t ERROR \t {classname} \t {msg}"); } public static void UpdataLog(string msg) { //添加 LogList.Add(msg); //截断 if (LogList.Count > LogNum) LogList = LogList.GetRange(LogList.Count - LogNum, LogNum); } public static List GetLogList() { //返回 return LogList; } public static bool ClearLogList() { LogList = new List(); return true; } } public static class GetName { public static string GetCurrentName() { return System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; } } }