netcore读取配置文件的方法总结
//第1种读取配置文件方法
// 加载日志配置文件
//var setttins = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
//var dd = setttins["SeqLogServerUrl"];
//第2种读取配置文件方法
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((ctx, lc) => lc
.WriteTo.Console()
.WriteTo.Seq(builder.Configuration["SeqLogServerUrl"]));
//第3种读取配置文件方法
var builder1 = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) // 设置配置文件所在目录
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true);
IConfigurationRoot configuration = builder1.Build();
string setting1 = configuration["SeqLogServerUrl"];