当前位置:
首页 > Python基础教程 >
-
C#教程之NLog组件(2)
else if (operatorLogModel.LogLevel == NLog.LogLevel.Warn)
180 level = LogLevel.Warn;
181 else if (operatorLogModel.LogLevel == NLog.LogLevel.Error)
182 level = LogLevel.Error;
183 else if (operatorLogModel.LogLevel == NLog.LogLevel.Fatal)
184 level = LogLevel.Fatal;
185
186 if (operatorLogModel.LogMessage.Length > 3000)
187 {
188 operatorLogModel.LogMessage = operatorLogModel.LogMessage.Substring(0, 3000);
189 }
190 lei.Properties["Id"] = Guid.NewGuid().ToString("D");
191 lei.Properties["AppName"] = operatorLogModel.AppName;
192 lei.Properties["ModuleName"] = operatorLogModel.ModuleName;
193 lei.Properties["ProcName"] = operatorLogModel.ProcName;
194 lei.Properties["OperationType"] = operatorLogModel.OperationType;
195 lei.Properties["Logger"] = operatorLogModel.Logger;
196 lei.Properties["LogMessage"] = operatorLogModel.LogMessage;
197 lei.Properties["IP"] = operatorLogModel.IP ?? DefaultIP;
198 lei.Properties["Longdate"] = operatorLogModel.Longdate;
199 lei.Properties["UserName"] = operatorLogModel.UserName ?? DefaultUser;
200 lei.Properties["Createdate"] = operatorLogModel.Createdate;
201 lei.Level = operatorLogModel.LogLevel;
202 _logger.Log(level, lei);
203 }
204 #endregion
205 }
对操作类型进行简单封装,也可以自定义:
1 /// <summary> 2 /// 操作类型枚举 3 /// </summary> 4 public enum OperationType 5 { 6 /// <summary> 7 /// 保存或添加 8 /// </summary> 9 [System.ComponentModel.Description("添加")] 10 ADD, 11 /// <summary> 12 /// 更新 13 /// </summary> 14 [System.ComponentModel.Description("更新")] 15 UPDATE, 16 /// <summary> 17 /// 核销 18 /// </summary> 19 [System.ComponentModel.Description("核销")] 20 AUDIT, 21 /// <summary> 22 /// 查看 23 /// </summary> 24 [System.ComponentModel.Description("指派")] 25 ASSIGN, 26 /// <summary> 27 /// 删除 28 /// </summary> 29 [System.ComponentModel.Description("删除")] 30 DELETE, 31 /// <summary> 32 /// 读取/查询 33 /// </summary> 34 [System.ComponentModel.Description("查询")] 35 RETRIEVE, 36 /// <summary> 37 /// 登录 38 /// </summary> 39 [System.ComponentModel.Description("登录")] 40 LOGIN, 41 /// <summary> 42 /// 查看 43 /// </summary> 44 [System.ComponentModel.Description("查看")] 45 LOOK 46 }
自定义类,主要用于绑定数据:
1 /// <summary> 2 /// 操作日志类 3 /// </summary> 4 public class OperatorLogModel 5 { 6 /// <summary> 7 /// 自增主键ID 8 /// </summary> 9 public string Id { get; set; } 10 /// <summary> 11 /// 一级菜单 12 /// </summary> 13 public string AppName { get; set; } 14 /// <summary> 15 /// 二级菜单 16 /// </summary> 17 public string ModuleName { get; set; } 18 /// <summary> 19 /// 本级菜单 20 /// </summary> 21 public string ProcName { get; set; } 22 /// <summary> 23 /// 操作类型 24 /// </summary> 25 public int OperationType { get; set; } 26 /// <summary> 27 /// 日志文件 28 /// </summary> 29 public string Logger { get; set; } 30 /// <summary> 31 /// 日志信息 32 /// </summary> 33 public string LogMessage { get; set; } 34 /// <summary> 35 /// IP地址 36 /// </summary> 37 public string IP { get; set; } 38 /// <summary> 39 /// 记录时间 40 /// </summary> 41 public string Longdate { get; set; } 42 /// <summary> 43 /// 用户名称 44 /// </summary> 45 public string UserName { get; set; } 46 /// <summary> 47 /// 日志级别 48 /// </summary> 49 public NLog.LogLevel LogLevel { get; set; } 50 /// <summary> 51 /// 创建时间 52 /// </summary> 53 public DateTime Createdate { get; set; } 54 }
创建数据库表,字段可以自定义,此处用的是SQL Server:
1 CREATE TABLE [dbo].[OperatorLog]( 2 [Id] [varchar](60) NOT NULL, 3 [AppName] [varchar](20) NOT NULL, 4 [ModuleName] [varchar](30) NOT NULL, 5 [ProcName] [varchar](30) NOT NULL, 6 [OperationType] [int] NOT NULL, 7 [Logger] [varchar](500) NOT NULL, 8 [LogMessage] [varchar](3000) NOT NULL, 9 [IP] [varchar](32) NOT NULL, 10 [UserName] [varchar](36) NOT NULL, 11 [Createdate] [datetime] NOT NULL, 12 [LogLevel] [varchar](12) NOT NULL, 13 CONSTRAINT [PK_OperatorLog] PRIMARY KEY CLUSTERED 14 ( 15 [Id] ASC 16 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 17 ) ON [PRIMARY] 18 19 GO 20 21 SET ANSI_PADDING OFF 22 GO 23 24 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_Id] DEFAULT ('') FOR [Id] 25 GO 26 27 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_AppName] DEFAULT ('') FOR [AppName] 28 GO 29 30 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_ModuleName] DEFAULT ('') FOR [ModuleName] 31 GO 32 33 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_ProcName] DEFAULT ('') FOR [ProcName] 34 GO 35 36 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_OperationType] DEFAULT ((0)) FOR [OperationType] 37 GO 38 39 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_Logger] DEFAULT ('') FOR [Logger] 40 GO 41 42 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_LogMessage] DEFAULT ('') FOR [LogMessage] 43 GO 44 45 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_IP] DEFAULT ('') FOR [IP] 46 GO 47 48 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_UserName] DEFAULT ('') FOR [UserName] 49 GO 50 51 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF__OperatorL__creat__02084FDA] DEFAULT (getdate()) FOR [Createdate] 52 GO 53 54 ALTER TABLE [dbo].[OperatorLog] ADD CONSTRAINT [DF_OperatorLog_LogLevel] DEFAULT ('') FOR [LogLevel] 55 GO 56 57 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'日志表主键ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN'
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式