Have created a console application in .net core, i want to define date in appsettings.json and then access in program.cs,how can this be done
here is appsetting.json code i am trying
"date": {
"todayDate": ''new Date()'
}
please let me know about the same

Rajeesh MenothPosted Feb 22, 2022, 5:31 PM
Aniket NarvankarPosted Feb 22, 2022, 1:27 PM
hi rajeesh,
"date": {
"todayDate": ''{date}'
}
when i am trying to access this on .cs side it is getting me value as {date}
here is the code
username = _iconfig.GetSection("date").GetSection("todayDate").Value;
please do let me know how will i get current date
Rajeesh MenothPosted Feb 22, 2022, 11:56 AM
Hi,
You can use templating concept in json file.
C#:
While binding appsetting.json you can pass "date" properties into it.
Reference:
https://stackoverflow.com/questions/62909495/serilog-how-to-use-utc-date-in-file-name
https://stackoverflow.com/questions/66550450/how-to-use-expression-template-with-appsettings-in-serilog