
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"name": { "name": "testConfig" }
}
代码(.net core 6):
ConfigurationBuilder configBuilder = new ConfigurationBuilder();
configBuilder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);//, reloadonChange: false);
IConfigurationRoot config = configBuilder.Build();
//string name = config["name"];
//Console.WriteLine($"name={name}");
string proxyAddress = config.GetSection("Logging:LogLevel:Default").Value;
Console.WriteLine($"Address: {proxyAddress}");
控制台输出:
