using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Flyinsono.Client.Test.Utilities.Executors; namespace Flyinsono.Client.Test.Log { public class LogItem { /// /// Log level /// public LogLevel LogLevel { get; set; } /// /// Log content /// public string Content { get; set; } } public class LogEngineImplement : DefaultLogEngine { private SequenceExecutor _logSequenceExecutor = new SequenceExecutor("LogSequenceExecutor"); private DateTime _today; Action _actionShowLogger; public LogEngineImplement(Action action) { _actionShowLogger = action; } public override void Write(LogLevel level, string msg) { var message = RecombinateMessage(level, msg); _logSequenceExecutor.Add(ExecuteWrite, message); _actionShowLogger?.Invoke(new LogItem() { LogLevel = level, Content = message }); } private bool ExecuteWrite(string message) { try { if (DateTime.Today != _today) { InitializeLogger(); _today = DateTime.Today; } WriteMessage(message); } catch { } return true; } public override void Dispose() { _logSequenceExecutor.Dispose(); base.Dispose(); } } }