42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using System;
|
||
using System.Runtime;
|
||
using Hncore.Infrastructure.Serializer;
|
||
using Microsoft.AspNetCore.Hosting;
|
||
using Microsoft.Extensions.Configuration;
|
||
|
||
namespace Hncore.Infrastructure.WebApi
|
||
{
|
||
public static class HostingEnvironmentExtend
|
||
{
|
||
public static IConfigurationRoot UseAppsettings(this IHostingEnvironment env)
|
||
{
|
||
Console.WriteLine("环境:" + Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"));
|
||
#if DEBUG
|
||
Console.WriteLine("模式:DEBUG");
|
||
#endif
|
||
|
||
#if RELEASE
|
||
Console.WriteLine("模式:RELEASE");
|
||
#endif
|
||
|
||
Console.WriteLine("GC模式:" + new
|
||
{
|
||
IsServerGC = GCSettings.IsServerGC,
|
||
LargeObjectHeapCompactionMode = GCSettings.LargeObjectHeapCompactionMode.ToString(),
|
||
LatencyMode = GCSettings.LatencyMode.ToString()
|
||
}.ToJson(true));
|
||
|
||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||
|
||
var builder = new ConfigurationBuilder()
|
||
.SetBasePath(env.ContentRootPath)
|
||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false)
|
||
.AddEnvironmentVariables();
|
||
|
||
var config = builder.Build();
|
||
|
||
return config;
|
||
}
|
||
}
|
||
} |