using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HBLConsole.Service
{
public class MessageLog
{
private volatile static MessageLog _Instance;
public static MessageLog GetInstance => _Instance ?? (_Instance = new MessageLog());
private MessageLog() { }
private static readonly object _lock = new object();
#region 普通消息日志
///
/// 日志显示委托
///
public Action InfoNotify { get; set; }
///
/// 日志信息
///
public string LogInfo { get; set; } = string.Empty;
///
/// 普通日志输出
///
///
public void Show(string info, Color color = default(Color))
{
lock (_lock)
{
if (color.A == 0 && color.R == 0 && color.G == 0 && color.B == 0) color = Color.Aqua;
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
LogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {LogInfo}";
if (InfoNotify != null) InfoNotify(info, color);
}
}
#endregion
#region 异常消息日志
///
/// 异常日志委托
///
public Action ExInfoNotify { get; set; }
///
/// 异常日志信息
///
public string ExLogInfo { get; set; } = string.Empty;
///
/// 异常日志输出
///
///
public void ShowEx(string info, Color color = default(Color))
{
lock (_lock)
{
color = Color.Red;
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}";
if (ExInfoNotify != null) ExInfoNotify(info, color);
}
}
#endregion
}
}