修改环境
parent
25d07ecf8b
commit
6451f15ed6
|
@ -19,22 +19,33 @@ namespace IRaCIS.Core.API
|
|||
{
|
||||
try
|
||||
{
|
||||
//以配置文件为准,否则 从url中取环境值(服务以命令行传递参数启动,配置文件配置了就不需要传递环境参数)
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
var enviromentName = config["ASPNETCORE_ENVIRONMENT"];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(enviromentName))
|
||||
{
|
||||
|
||||
var index = Array.IndexOf(args, "--env");
|
||||
var environment = index > -1
|
||||
enviromentName = index > -1
|
||||
? args[index + 1]
|
||||
: "Development";
|
||||
}
|
||||
|
||||
//Dicom 浏览
|
||||
//ImageManager.SetImplementation(WinFormsImageManager.Instance);
|
||||
|
||||
var host = CreateHostBuilder(args)
|
||||
.UseEnvironment(environment) //命令行传入环境
|
||||
.UseEnvironment(enviromentName) //命令行传入环境
|
||||
.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
|
||||
//Console.WriteLine(hostContext.HostingEnvironment.EnvironmentName);
|
||||
config.AddJsonFile("appsettings.json", false, true)
|
||||
.AddJsonFile($"appsettings.{environment}.json", false, true);
|
||||
.AddJsonFile($"appsettings.{enviromentName}.json", false, true);
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
@ -46,7 +57,7 @@ namespace IRaCIS.Core.API
|
|||
|
||||
|
||||
//// Serilog
|
||||
SerilogExtension.AddSerilogSetup(environment, host.Services);
|
||||
SerilogExtension.AddSerilogSetup(enviromentName, host.Services);
|
||||
|
||||
//缓存项目的状态 匿名化数据
|
||||
await InitCache(host);
|
||||
|
@ -55,7 +66,7 @@ namespace IRaCIS.Core.API
|
|||
|
||||
host.Run();
|
||||
|
||||
Log.Logger.Warning($"当前环境:{environment}");
|
||||
Log.Logger.Warning($"当前环境:{enviromentName}");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
Loading…
Reference in New Issue