Question: appsettings.json and appsettings.environment.json for ASP.NET Core
See original GitHub issueASP.NET Core appsettings.json
files can be used additively for different environments, e.g.:
.AddJsonFile("appsettings.json", optional:false)
.AddJsonFile("appsettings.Development.json", optional:true)
The latter adds to the former.
Let’s say I always want file sink, but console sink only in development. So I add file sink to appsettings.json
and console sink to appsettings.Development.json
.
But in development, the result is that file sink is ignored. If I want it then I must add it to both files, which is a bad idea as copy-paste mistakes will happen one day.
Am I doing this correctly?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
c# - Automatically set appsettings.json for dev and release ...
First, add a key to your launch.json file. · Then, in your project, create a new appsettings.{environment}. · And finally, configure it to...
Read more >How to create environments with appSettings?
How to create environments with appSettings? · Add a appsettings.Home.json file to the project. · Add the setting to the file, for example:...
Read more >Configuration in ASP.NET Core
Environment variable names reflect the structure of an appsettings.json file. Each element in the hierarchy is separated by a double underscore ...
Read more >ASP.NET Core AppSettings.json file
The appsettings.json file is the application configuration file that is used to store configuration settings such as database connection strings, any ...
Read more >Multiple appsettings.json in .net core without using an ...
This idea is great if you have one server dedicated to one . net core application, which is usually not the case.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lonix1 json array syntax is a syntatic sugar here.
is equal to:
where
0
is element index in the array.Microsoft.Extension.Configuration
is build around key-value dictionary so each configuration key must have unique path. So in your case you overwrite the first element in theappsettings.Development.json
. Workaround will be any other name (not0
):Problem is it now gives
System.InvalidOperationException: The configuration value in Serilog:WriteTo:0:Name has no 'Name' element.
However when I remove the array then it works. Since I’m only using one sink in that configuration, it’s good enough for me. Thanks.