一、文件变更的监听事件
var builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json",false,true); var configurationRoot = builder.Build();
//执行变革回调函数 ChangeToken.OnChange(() => configurationRoot.GetReloadToken(), () => { Console.WriteLine($"Key1:{configurationRoot["Key1"]}"); Console.WriteLine($"Key2:{configurationRoot["Key2"]}"); Console.WriteLine($"Key3:{configurationRoot["Key3"]}"); });