Exemple #1
0
        public static void InitConfig(string configPath, string fileName)
        {
            try
            {
                var builder = new ConfigurationBuilder().SetBasePath(configPath);//SetBasePath 需要添加Microsoft.Extensions.Configuration.Json引用  Directory.GetCurrentDirectory()取得是C盘目录

                builder.AddJsonFile(fileName);

                Configuration = builder.Build();
            }
            catch (Exception e)
            {
                NLogHelper.LogError(e.ToString());
                throw e;
            }
        }
Exemple #2
0
        public static void InitConfig()
        {
            try
            {
                string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);


                var builder = new ConfigurationBuilder().SetBasePath(path);//SetBasePath 需要添加Microsoft.Extensions.Configuration.Json引用  Directory.GetCurrentDirectory()取得是C盘目录

                string evname = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

                builder.AddJsonFile("appsettings.json").AddJsonFile($"appsettings.{evname}.json");

                Configuration = builder.Build();
                IsOnline      = GetSectionValue("IsOnline");
            }
            catch (Exception e)
            {
                NLogHelper.LogError(e.ToString());
            }
        }