我想忽略生產系統中的某些警告。我得到的等效代碼是這樣的:
optionsBuilder
.ConfigureWarnings(x => x.Ignore(RelationalEventId.MultipleCollectionIncludeWarning));
是否可以設定忽略appSettings.Production.json?
目前是:
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.EntityFrameworkCore": "Warning",
"IdentityServer4": "Information"
}
},
uj5u.com熱心網友回復:
我不是 EF Core 專家,但很明顯這是兩種不同型別的配置;構建器呼叫告訴 EF Core 要記錄或不記錄哪些事件,而 appsettings 只是指示日志記錄框架哪些提供程式在哪些級別進行偵聽。您可能能夠在給定的日志級別使整個提供程式靜音,但這可能不夠細化,無法僅過濾該提供程式中的某一類日志事件。
如果 EF Core 沒有用于從 Configuration 物件中讀取 Options 類的本機機制,并且您想要管理的開關集有限(即,只有一組可以一起打開或關閉的事物) ,那么你可以自己撰寫來幫助管理它。
配置類:
public class CustomEfCoreLoggingOptions
{
public const string Section = "CustomEfCoreLogging";
public bool IgnoreMultipleCollectionIncludeWarning { get; set; }
}
應用設定:
"CustomEfCoreLogging" : {
"IgnoreMultipleCollectionIncludeWarning" : true
}
在您的啟動中:
var efLogging = Configuration.GetSection(CustomEfCoreLoggingOptions.Section).Get<CustomEfCoreLoggingOptions>();
var optionsBuilder = new DbContextOptionsBuilder();
if (efLogging.IgnoreMultipleCollectionIncludeWarning) optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.MultipleCollectionIncludeWarning));
//...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347651.html
標籤:asp.net核心 日志记录 .net核心 实体框架核心
