Serilog
Lio 2021-04-06 日志配置
# Serilog使用
首先,当然是引用nuget程序包(Serilog.AspNetCore),然后需要添加log4net的配置文件,该文件在项目中CfgFiles文件夹下创建log4net.xml,并且设置属性如果较新则复制
在配置文件中添加配置
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Fatal",
"System": "Fatal"
}
},
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "RollingFile",
"Args": {
"pathFormat": "logs/{Date}.log",
"outputTemplate": "{Timestamp:HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
"shared": true,
"restrictedToMinimumLevel": "Debug"
}
},
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "Data Source=106.15.94.246;Initial Catalog=TestBlog;Persist Security Info=True;User ID=sa;Password=lt863370814..",
//"connectionString": "Data Source=106.15.94.246;Initial Catalog=Blog;Persist Security Info=True;User ID=sa;Password=lt863370814..",
//"schemaName": "EventLogging",
"tableName": "T_SYS_SERILOGS",
"autoCreateSqlTable": true,
"restrictedToMinimumLevel": "Debug",
"batchPostingLimit": 100,
"period": "0.00:00:30",
"columnOptionsSection": {
"disableTriggers": true,
"clusteredColumnstoreIndex": false,
"primaryKeyColumnName": "Id",
"addStandardColumns": [ "LogEvent" ],
"removeStandardColumns": [ "MessageTemplate" ],
"additionalColumns": [
{
"ColumnName": "IP",
"DataType": "varchar",
"DataLength": 32
}
],
"id": { "nonClusteredIndex": true },
"properties": {
"columnName": "Properties",
"excludeAdditionalProperties": true,
"dictionaryElementName": "dict",
"itemElementName": "item",
"omitDictionaryContainerElement": false,
"omitSequenceContainerElement": false,
"omitStructureContainerElement": false,
"omitElementIfEmpty": true,
"propertyElementName": "prop",
"rootElementName": "root",
"sequenceElementName": "seq",
"structureElementName": "struct",
"usePropertyKeyAsElementName": false
},
"timeStamp": {
"columnName": "Timestamp",
"convertToUtc": true
},
"logEvent": {
"excludeAdditionalProperties": true,
"excludeStandardColumns": true
},
"message": { "columnName": "message" },
"exception": { "columnName": "exception" }
}
}
}
]
}
}
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
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