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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#region
 
using System;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.DataAccess;
using CSFrameworkV5.Interfaces;
using CSFrameworkV5.Models;
using CSFrameworkV5.WebRef.CommonService;
 
#endregion
 
namespace CSFrameworkV5.Business
{
    /// <summary>
    ///     数据库日志
    /// </summary>
    public class LogDB : ILogUserOperate
    {
        private IBridge_Log _Log;
 
        public LogDB()
        {
            _Log = CreateLogData();
        }
 
        private IBridge_Log CreateLogData()
        {
            //DB日志要测试数据库连接
            BridgeFactory.TestConnection(true);
 
            if (BridgeFactory.IsADODirect)
                return new dalLog(Loginer.CurrentUser);
 
            if (BridgeFactory.IsWCFBridge) return new WCF_OperateLog();
 
            throw new CustomException(BridgeFactory.UNKNOW_BRIDGE_TYPE);
        }
 
        private string GetStr(string content, int length)
        {
            if (string.IsNullOrEmpty(content)) return "";
 
            var max = content.Length;
            if (max > length) max = length;
 
            return content.Substring(0, max);
        }
 
        #region 数据日志单例
 
        private static LogDB _Instance;
 
        public static LogDB Log
        {
            get
            {
                if (_Instance == null) _Instance = new LogDB();
 
                return _Instance;
            }
        }
 
        #endregion;
 
        //在数据库建张Log表,实现相应接口
 
        #region IOperateLog Members
 
        public void WriteLog(LogTypeSystem type, string content)
        {
            try
            {
                var log = new sys_LogOperation();
                log.Account = Loginer.CurrentUser.Account;
                log.MSG = GetStr(content, 98); //最长98个字符
                log.OperationTime = DateTime.Now;
                log.OperationType = type.ToStringEx();
                log.FormName = "";
                log.MenuName = "";
                log.FormCaption = "";
                _Log.WriteLog(log);
            }
            catch
            {
                //写日志失败,不抛出异常
            }
        }
 
        public void WriteLog(LogTypeSystem type, string content,
            string formName, string formCaption, string menuName)
        {
            try
            {
                var log = new sys_LogOperation();
                log.Account = Loginer.CurrentUser.Account;
                log.MSG = content;
                log.OperationTime = DateTime.Now;
                log.OperationType = type.ToStringEx();
                log.FormName = formName;
                log.FormCaption = formCaption;
                log.MenuName = menuName;
                _Log.WriteLog(log);
            }
            catch
            {
                //写日志失败,不抛出异常
            }
        }
 
        public void ClearLog(string user, DateTime beginDate, DateTime endDate)
        {
            try
            {
                _Log.ClearLog(user, beginDate, endDate);
            }
            catch
            {
                //写日志失败,不抛出异常
            }
        }
 
        public void WriteLog(string content)
        {
            try
            {
                _Log.WriteLog(content);
            }
            catch
            {
                //写日志失败,不抛出异常
            }
        }
 
        public void ClearLog(DateTime beginDate, DateTime endDate)
        {
            try
            {
                _Log.ClearLog(beginDate, endDate);
            }
            catch
            {
                //写日志失败,不抛出异常
            }
        }
 
        public void ClearAll()
        {
            try
            {
                _Log.ClearAll();
            }
            catch
            {
                //写日志失败,不抛出异常
            }
        }
 
        #endregion
    }
 
    //兼容原有的DBLog类,请使用LogDB类
    public class DBLog : LogDB
    {
    }
}