I have a .NET Core 2.0 console application which has a AppConfiguration file which provides different app-settings. I have added in the main-method the creation of a ConfigurationBuilder
object and added the reloadOnChange
flag for that JSON file like in the code below.
static void Main(string[] args)
{
Console.WriteLine("Program started...");
Console.WriteLine("Stop Program by Ctrl+C");
//Add Exit Possibility
Console.CancelKeyPress += CurrentDomain_ProcessExit;
//Add Configuration Builder
Console.Write("Load Shared Configuration...");
Configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("SharedAppConfiguration.json", optional: false, reloadOnChange: true)
.Build();
Console.WriteLine("done");
}
How can I catch or get information about the event, that the JSON file "SharedAppConfiguration.json" has changed?
I've tried to do something like this:
Configuration.GetSection("AppConfiguration").Bind(appConfiguration);
But like it looks, there is no .Bind
method in .NET Core console application - in ASP.NET it’s available.