标签:format first lin return info readonly conf col ado
1.配置文件
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "wizards": [ { "Name": "Gandalf", "Age": "1000" }, { "Name": "Harry", "Age": "17" } ], "AllowedHosts": "*" }
2.读取方法
public class FirstController : Controller { private readonly ILogger<FirstController> _logger; private readonly IConfiguration _iConfiguration; public FirstController(ILogger<FirstController> logger, IConfiguration iConfiguration) { _logger = logger; _iConfiguration = iConfiguration; } public IActionResult Index() { string Urls = _iConfiguration["Urls"]; string LogLevel = _iConfiguration["Logging:LogLevel:Default"]; string Name = _iConfiguration["wizards:0:Name"]; Console.WriteLine("Name:" + Name); Console.WriteLine("LogLevel:" + LogLevel); Console.WriteLine("Urls:" + Urls); //运行时的url _logger.LogWarning("测试日志"); return View(); } }
标签:format first lin return info readonly conf col ado
原文地址:https://www.cnblogs.com/wangdash/p/12420122.html