using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ips.Library.Basic { public class IpsLogger { public static event EventHandler Logged; public static void Info(string msg, bool writeToUI = true) { Log(LogType.Info, msg, null, writeToUI); } public static void Warn(string msg, Exception ex = null, bool writeToUI = true) { Log(LogType.Warn, msg, ex, writeToUI); } public static void Error(string msg, Exception ex = null, bool writeToUI = true) { Log(LogType.Error, msg, ex, writeToUI); } public static void Log(LogType logType, string logContent, Exception ex = null, bool writeToUI = true) { Logged?.Invoke(null, new IpsLogEventArg(logType, logContent, ex, writeToUI)); } } public enum LogType { [Description("消息")] Info, [Description("警告")] Warn, [Description("错误")] Error } public class IpsLogEventArg : EventArgs { public IpsLogEventArg(LogType logType, string content, Exception ex = null, bool writeToUI = true) { LogType = logType; Content = content; this.Exception = ex; WriteToUI = writeToUI; } public LogType LogType { get; set; } public string Content { get; set; } public Exception Exception { get; set; } public bool WriteToUI { get; set; } } }