我有一个ApplicationConfigurationSettings类,我将appsettings.json文件中的值绑定到。我可以获取除记录器LogLevel值之外的所有绑定,很可能是由于Logging条目的json格式中存在子级别。
我按如下方式绑定类
services.Configure<ApplicationConfigurationSettings>(Configuration.GetSection("ApplicationConfiguration"));
appsettings.json(为简洁起见,删除了部分)
{
"ApplicationConfiguration": {
"ConnectionStrings": {
"DevelopmentConnection": "Server=(localdb)\\mssqllocaldb;Database=TestingConfigurationNetCoreTwo_Development;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ApplicationIconUrls": {
"MaleUserIcon": "https://machineryrestorations.blob.core.windows.net/publicfiles/images/BestMaleUser_32x32.png",
"FemaleUserIcon": "https://machineryrestorations.blob.core.windows.net/publicfiles/images/BestFemaleUser_32x32"
},
"ApplicationInfo": {
"VersionNumber": "1.0.0",
"Author": "Jimbo",
"ApplicationName": "CustomTemplate",
"CreatedOn": "November 20, 2017"
}
}
}
我的记录器POCO
public class LoggerSettings
{
public bool IncludeScopes { get; set; }
public KeyValuePair<string,string> LogLevel { get; set; }
}
我确定这是因为活页夹无法将我的LogLevel属性与json文件中的内容进行协调。如何更改记录器POCO以使其工作,因为我无法更改json文件中的记录格式?
这是json提供程序在从
检查配置时解析它的方式services.AddSingleton(Configuration);
{[ApplicationConfiguration:Logging:IncludeScopes,False]} {[ApplicationConfiguration:Logging:LogLevel:Default,Warning]}
我似乎无法在类中正确设置该属性,因此它可以正确绑定。