当前位置:
首页 > Python基础教程 >
-
C#教程之NLog组件(3)
,@level2name=N'Id'
58 GO
59
60 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'一级菜单' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'AppName'
61 GO
62
63 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'二级菜单' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'ModuleName'
64 GO
65
66 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本级菜单' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'ProcName'
67 GO
68
69 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'操作类型' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'OperationType'
70 GO
71
72 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'日志文件' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'Logger'
73 GO
74
75 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'日志内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'LogMessage'
76 GO
77
78 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'IP地址' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'IP'
79 GO
80
81 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'用户名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'UserName'
82 GO
83
84 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'Createdate'
85 GO
86
87 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'日志级别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OperatorLog', @level2type=N'COLUMN',@level2name=N'LogLevel'
88 GO
引用日志如下:
1 public class Program 2 { 3 public static void Main(string[] args) 4 { 5 OperatorLogModel opModel = new OperatorLogModel(); 6 opModel.AppName = "系统管理"; 7 opModel.ModuleName = "权限管理"; 8 opModel.ProcName = "用户管理"; 9 opModel.OperationType = Convert.ToInt32(Enum.Parse(typeof(OperationType), OperationType.RETRIEVE.ToString())); 10 opModel.UserName = "ss"; 11 //opModel.LogLevel = NLog.LogLevel.Trace; 12 opModel.Longdate = DateTime.Now.ToString(); 13 opModel.Createdate = DateTime.Now; 14 opModel.Logger = "dfdfd"; 15 opModel.LogMessage = "测试测试测试!!!"; 16 Logger.Default.Error("dsfsfsfd"); 17 //string ip = Request.HttpContext.Connection.RemoteIpAddress.ToString(); 18 19 //Logger.Default.Info("就是这么霸气"); 20 21 Logger.Default.InsOperatorLog(opModel); 22 CreateWebHostBuilder(args).Build().Run(); 23 } 24 25 public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 26 WebHost.CreateDefaultBuilder(args) 27 .UseStartup<Startup>(); 28 }
数据库插入的操作日志结果如下:
文件中记录的日志如下:
以上就是NLog日志组件的简单封装,欢迎纠错!!!