1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using Vinno.IUS.Common.Log;
- using Vinno.IUS.Common.Utilities.Executors;
- namespace Flyinsono.Client.Test
- {
- public class LogItem
- {
- /// <summary>
- /// Log level
- /// </summary>
- public LogLevel LogLevel { get; set; }
- /// <summary>
- /// Log content
- /// </summary>
- public string Content { get; set; }
- }
- public class LogEngineImplement : DefaultLogEngine
- {
- private SequenceExecutor<string> _logSequenceExecutor = new SequenceExecutor<string>("LogSequenceExecutor");
- private DateTime _today;
-
- Action<LogItem> _actionShowLogger;
- public LogEngineImplement(Action<LogItem> 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();
- }
- }
- }
|