#region
|
|
using System;
|
using System.Collections.Generic;
|
using System.Windows.Forms;
|
|
#endregion
|
|
namespace CSFrameworkV5.Common
|
{
|
/// <summary>
|
/// 系统操作日志管理器,管理多种日志
|
/// </summary>
|
public static class LogUserOperate
|
{
|
private static List<ILogUserOperate> _Logs;
|
|
static LogUserOperate()
|
{
|
_Logs = new List<ILogUserOperate>();
|
}
|
|
/// <summary>
|
/// 已注册的日志实例
|
/// </summary>
|
public static List<ILogUserOperate> Logs => _Logs;
|
|
/// <summary>
|
/// 登记日志实例,系统支持不同类型的日志
|
/// </summary>
|
/// <param name="log">日志实例</param>
|
public static void RegisteLog(ILogUserOperate log)
|
{
|
if (_Logs == null) _Logs = new List<ILogUserOperate>();
|
|
_Logs.Add(log);
|
}
|
|
/// <summary>
|
/// 写入日志
|
/// </summary>
|
/// <param name="content">日志内容</param>
|
/// <param name="host">宿主,调用日志接口的对象实例</param>
|
public static void Write(string content, object host)
|
{
|
if (host != null) content = host.GetType().Name + ":" + content;
|
|
foreach (var log in _Logs) log.WriteLog(content);
|
}
|
|
public static void Write(Exception ex)
|
{
|
if (ex == null) return;
|
|
var type = ex is CustomException
|
? LogTypeSystem.CustomError
|
: LogTypeSystem.Exception;
|
foreach (var log in _Logs) log.WriteLog(type, ex.Message);
|
}
|
|
/// <summary>
|
/// 写入指定类型的日志
|
/// </summary>
|
/// <param name="type"></param>
|
/// <param name="content"></param>
|
public static void Write(LogTypeSystem type, string content)
|
{
|
if (string.IsNullOrEmpty(content)) return;
|
|
foreach (var log in _Logs) log.WriteLog(type, content);
|
}
|
|
/// <summary>
|
/// 写入日志
|
/// </summary>
|
/// <param name="message">日志内容</param>
|
public static void Write(string content)
|
{
|
if (string.IsNullOrEmpty(content)) return;
|
|
foreach (var log in _Logs) log.WriteLog(content);
|
}
|
|
/// <summary>
|
/// 打开窗体动作写入日志
|
/// </summary>
|
/// <param name="content"></param>
|
/// <param name="form"></param>
|
/// <param name="menuName"></param>
|
public static void WriteOpenFormLog(Form form, string content,
|
string menuName)
|
{
|
if (form == null || string.IsNullOrEmpty(content)) return;
|
|
foreach (var log in _Logs)
|
log.WriteLog(LogTypeSystem.OpenForm, content, form.Name,
|
form.Text, menuName);
|
}
|
}
|
}
|