1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#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);
        }
    }
}