Hello guys,
I have this .net core 3.1 console app that is running on a windows task scheduler. The problem is if I change the appsettings.json, it does not make any changes. How can I fix this?
Here is my Program.cs:
class Program
{
static async Task Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File("log-.txt",LogEventLevel.Information, rollingInterval: RollingInterval.Day)
.WriteTo.Email(new EmailConnectionInfo
{
FromEmail = "test@enggaming.com",
ToEmail = "anon@user ",
MailServer = "smtp.yandex.com.tr",
NetworkCredentials = new NetworkCredential
{
UserName = "test@test.com",
Password = "123"
},
EnableSsl = false,
Port = 587,
EmailSubject = "Game Purchase Service Error"
}, restrictedToMinimumLevel: LogEventLevel.Error, batchPostingLimit: 1)
.CreateLogger();
var builder = new HostBuilder()
.ConfigureServices((hostContext, services) =>
{
//Serilog
services.AddLogging(loggingBuilder =>
loggingBuilder.AddSerilog(dispose: true));
//Setting up API Client
services.AddHttpClient("OrdersClient", client =>
{
client.BaseAddress =
new Uri("https://testapi.com/orders?status=Created");
client.DefaultRequestHeaders.Add("Accept", "application/json");
});
services.AddSingleton<IHostedService, BusinessService>();
//Setting up app settings configuration
var config = LoadConfiguration();
services.AddSingleton(config);
});
await builder.RunConsoleAsync();
}
public static IConfiguration LoadConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(path: "serilog.json", optional: false, reloadOnChange: true);
return builder.Build();
}
}
Here is the appsettings.json:
}
"Size": {
"Production": "1"
}
}
Here is the portion I am using appsettings.json:
...
var response = await httpClient.GetAsync("https://api.test.com/orders?status=Created&size="+ _configuration["Size:Production"]);