netcore 读取配置文件

 public class ManagerConfig
    {
        private static readonly IHostingEnvironment _hostingEnvironment = ObjectContainer.Current.Resolve<IHostingEnvironment>();

        public static string GetManagerConfig(string keyName)
        {
            var builder = new ConfigurationBuilder()
            .SetBasePath(_hostingEnvironment.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{_hostingEnvironment.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
            var configuration = builder.Build();
            return configuration[keyName].ToString();
        }
    }
原文地址:https://www.cnblogs.com/lostsea/p/11573153.html