ASP.NET Core 2.0 Configuration with XML/Json File
Ref: https://joonasw.net/view/asp-net-core-1-configuration-deep-dive
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.SetBasePath(_env.ContentRootPath);
configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
configurationBuilder.AddXmlFile("appsetting.xml",false, true);
var configuration = configurationBuilder.Build();
var value = configuration["Logging:IncludeScopes"];
string adminEmail1 = configuration["SiteSettings:AdminEmail"];
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.SetBasePath(_env.ContentRootPath);
configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
configurationBuilder.AddXmlFile("appsetting.xml",false, true);
var configuration = configurationBuilder.Build();
var value = configuration["Logging:IncludeScopes"];
string adminEmail1 = configuration["SiteSettings:AdminEmail"];
xml file:
<configuration>
<SiteSettings>
<AdminEmail>user@localhost</AdminEmail>
<UploadFolder>Uploads</UploadFolder>
<Logo>/images/logo.png</Logo>
<Timeout>20</Timeout>
</SiteSettings>
</configuration>
Json File
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}
Comments
Post a Comment