using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using log4net; using System.Windows.Forms; namespace Logger { public class LoggerClass { public static readonly ILog loginfo = LogManager.GetLogger("loginfo"); public static readonly ILog logerror = LogManager.GetLogger("logerror"); /// /// Log队列 /// public static Queue logQueue { get; set; } = new Queue() { }; public static void WriteLog(string info, bool ShowMsgBox = false) { if (loginfo.IsInfoEnabled) { loginfo.Info(info); } logQueue.Enqueue(new LogInfo{ message = info, ex = null, logLevel = MsgLevel.Info}); if(ShowMsgBox) { MessageBox.Show(info); } } public static void WriteLog(string info, MsgLevel msgLevel, bool ShowMsgBox = false) { if (loginfo.IsInfoEnabled) { loginfo.Info(info); } logQueue.Enqueue(new LogInfo { message = info,ex = null, logLevel = msgLevel }); if (ShowMsgBox) { MessageBox.Show(info); } } public static void WriteLog(string info, MsgLevel msgLevel, Exception ex, bool ShowMsgBox = false) { if (logerror.IsErrorEnabled) { logerror.Error(info, ex); } logQueue.Enqueue(new LogInfo { message = info, ex = ex, logLevel = msgLevel }); if (ShowMsgBox) { MessageBox.Show(info); } } public static void WriteLog(string info, Exception ex, bool ShowMsgBox = false) { if (logerror.IsErrorEnabled) { logerror.Error(info, ex); } logQueue.Enqueue(new LogInfo { message = info, ex = ex, logLevel = MsgLevel.Exception }); if (ShowMsgBox) { MessageBox.Show(info); } } } public class LogInfo { public string message { get; set; } public MsgLevel logLevel { get; set; } public Exception ex { get; set; } } public enum MsgLevel { /// /// 0.调试信息输出 /// Debug = 0, /// /// 1.业务信息记录 /// Info = 1, /// /// 2.警告提醒(捕获的业务异常) /// Warn = 2, /// /// 3.发生了异常(捕获的系统异常) /// Exception = 3, /// /// 4.发生致命异常(未被捕获的异常|捕获的业务逻辑异常) /// Fatal = 4 } }