CS 系统框架二[简单记录系统日志]

园子里面有几位朋友跟我说最好可以记录一些相关的日志,以便据此查找一些其它的信息或者是DeBug,我简单的处理了一下,

这里用到了一个枚举:

需要用的时候就传一个标志进来就行了,记录日志的函数就不说了,说白了就是记录一些数据,后台调用如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace Allen.Tools.Common
 7 {
 8     public static class SystemLog
 9     {
10         public static string GetLogType(int Type)
11         {
12             if (Type == 1)
13             {
14                 return "操作日志";
15             }               
16             else if (Type == 2)
17             {
18                 return "安全日志";
19             }
20             else if (Type == 3)
21             {
22                 return "访问日志";
23             }
24             else 
25             {
26                 return "不确定的类型";
27             }
28                 
29         }
30     }
31 }
 1 private void tsSave_Click(object sender, EventArgs e)
 2         {
 3             string FunctionName = txtItemName.Text.Trim();
 4             string FrmName = txtFrmName.Text.Trim();
 5             string MenuGroupID = this.cmbMenuGroupName.SelectedValue.ToString();
 6             string ICO = this.cmbICO.Text.Trim();
 7             string FrmCode = this.txtFunCode.Text.Trim();
 8             string IsAutoLoad = rdoAutoLoad.Checked ? "1" : "0";
 9             switch (intType)
10             {
11                 case 1:
12                     if (new BLL.sys_FunctionManager().CreateFunction(FunctionName, MenuGroupID, FrmName, ICO))
13                     {
14                         MessageText = "子菜单资料创建成功!\r\n【子菜单】:" + FunctionName;
15                         MessageBox.Show(MessageText, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
16 
17                     }                                   
18                     break;
19 
20                 case 2:
21                     if (new BLL.sys_FunctionManager().UpdateFunction(FunctionName, MenuGroupID, FrmName, ICO))
22                     {
23                         MessageText = "子菜单资料修改成功!\r\n【子菜单】:" + FunctionName;
24                         MessageBox.Show(MessageText , "提示信息:", MessageBoxButtons.OK, MessageBoxIcon.Information);
25                     }
26                    
27                     break;
28             }
29             tsCreate.Enabled = true;
30             tsChange.Enabled = true;
31             tsDelete.Enabled = true;
32             tsClose.Enabled = true;
33             tsSave.Enabled = false;
34             tsWaiver.Enabled = false;
35             blType = false;
36             FrmFunction_Shown(sender, e);           
37 
38             #region 记录系统日志
39             try
40             {
41                 if (intType == 1)
42                 {
43                     ExecMethodName = "BLL.sys_FunctionManager().CreateFunction";
44                 }
45                 if (intType == 2)
46                 {
47                     ExecMethodName = "BLL.sys_FunctionManager().UpdateFunction";
48                 }
49                 new BLL.PublicManager().CreateSystemLog(allensingleton.UserID,
50                     ExecMethodName, MessageText, SystemLog.GetLogType(1).ToString());
51             }
52             catch (Exception)
53             {
54             }
55             #endregion
56         }

这里因为创建和修改在同一个事件(Save的事件)里面实现的,所以我用if来判断了一下,如果是单一的情况则不需要这样处理了,日志记录如下图:

本来想把用户每一步操作的SQL语句给记下来的,但是发现有的字符串非常的长,包括那些参数,所以就只记录了当时执行的函数名称。

PS:    我把代码整理了一下,看起来比之前规范了一些,应该不会被移除首页了吧...

【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/allen0118/p/2760236.html