在我appsettings.json我已經寫了:如何使用Serilog的ReadFrom.KeyValuePairs方法?
{
"Logging": {
"PathLogsFile": "./Logs",
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
,在我startup.cs文件中構造
var pathLogsFile = Configuration["Logging:PathLogsFile"];
var logLevelApp = Configuration.GetSection("Logging:LogLevel:Default");
Log.Logger = new LoggerConfiguration()
.ReadFrom.KeyValuePairs(new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>(logLevelApp.Key, logLevelApp.Value)
}.ToDictionary(x => x.Key, x => x.Value))
.Enrich.FromLogContext()
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(evt => evt.Level == Serilog.Events.LogEventLevel.Error)
.WriteTo.RollingFile(Path.Combine(pathLogsFile, "error-{Date}.log")))
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(evt => evt.Level >= Serilog.Events.LogEventLevel.Debug)
.WriteTo.RollingFile(Path.Combine(pathLogsFile, "log-{Date}.log")))
.CreateLogger();
但是從AppSettings的讀不在最低水平。 任何想法?我該如何解決?
請不要強制標籤進入標題。閱讀關於如何正確使用標籤的幫助中心文章http://stackoverflow.com/help/tagging – Tseng
對不起@Tseng – FabioBit