"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%" } }