Serilog Json配置
"Serilog": { //日志等级有小到大:Verbose->Debug->Information->Warning->Error->Fatal "Using": [ "Serilog.Sinks.RollingFile", "Serilog.Sinks.Console", "Serilog.Filters.Expressions" ], "MinimumLevel": { "Default": "Debug", "Override": { "Microsoft": "Debug", //将Microsoft前缀的日志的最小输出级别改成Information "System": "Debug", //将System前缀的日志的最小输出级别改成Information, "Microsoft.AspNetCore": "Error", "Microsoft.AspNetCore.Cors.Infrastructure.CorsService": "Error", "Microsoft.AspNetCore.Mvc": "Verbose", "Microsoft.AspNetCore.Hosting": "Error" } }, "WriteTo": [ { "Name": "Console", "Args": { "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [{Level}] [{SourceContext}] {Message:lj}{NewLine}{Exception}" } }, { "Name": "RollingFile", "Args": { "pathFormat": "Logs\\ALL\\{Date}.log", //日志保存路径 "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}", //输出格式 "fileSizeLimitBytes": 5242880, //单个日志文件大小 "retainedFileCountLimit": 10, //日志保留最大数量 //"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog", //日志格式化格式 "buffered": false, //是否以流的形式写文件 "shared": true //是否允许文件多进程共享(buffered:true时,不可共享) } }, { "Name": "Logger", "Args": { "configureLogger": { "Filter": [ { "Name": "ByIncludingOnly", "Args": { "expression": "@Level = 'Debug'" } } ], "WriteTo": [ { "Name": "RollingFile", "Args": { "pathFormat": "Logs\\Debug\\{Date}.log", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} DEBUG {ClassName}:0 - [{Version}] [{HttpRequestIP}] [{AppName}] {Message:lj}{NewLine}{Exception}" } } ] } } }, { "Name": "Logger", "Args": { "configureLogger": { "Filter": [ { "Name": "ByIncludingOnly", "Args": { "expression": "@Level = 'Information'" } } ], "WriteTo": [ { "Name": "RollingFile", "Args": { "pathFormat": "Logs\\Info\\{Date}.log", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} INFO {ClassName}:0 - [{Version}] [{HttpRequestIP}] [{AppName}] {Message:lj}{NewLine}{Exception}" } } ] } } }, { "Name": "Logger", "Args": { "configureLogger": { "Filter": [ { "Name": "ByIncludingOnly", "Args": { "expression": "@Level = 'Error'" } } ], "WriteTo": [ { "Name": "RollingFile", "Args": { "pathFormat": "Logs\\Error\\{Date}.log", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} ERROR {ClassName}:0 - [{Version}] [{HttpRequestIP}] [{AppName}] {Message:lj}{NewLine}{Exception}" } } ] } } }, { "Name": "Logger", "Args": { "configureLogger": { "Filter": [ { "Name": "ByIncludingOnly", "Args": { "expression": "@Level = 'Warning'" } } ], "WriteTo": [ { "Name": "RollingFile", "Args": { "pathFormat": "Logs\\Warning\\{Date}.log", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} WARNING {ClassName}:0 - [{Version}] [{HttpRequestIP}] [{AppName}] {Message:lj}{NewLine}{Exception}" } } ] } } } ], "Enrich": [ "FromLogContext", "WithMachineName" ], "Properties": { "MachineName": "%COMPUTERNAME%" } }