Laden Sie umgebungsspezifische App-Einstellungsdateien mit Ausnahme von „Development“

- Listet die Dateien „appsettings.*.json“ im Stammverzeichnis des Inhalts auf
- Schließt „appsettings.Development.json“ vom Laden aus
- Fügt die verbleibenden JSON-Dateien zur Konfiguration hinzu
This commit is contained in:
2025-07-25 16:26:05 +02:00
parent f8e51e02a0
commit bf5566cefc
5 changed files with 86 additions and 74 deletions

View File

@@ -27,6 +27,12 @@ try
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
Directory
.GetFiles(builder.Environment.ContentRootPath, "appsettings.*.json", SearchOption.TopDirectoryOnly)
.Where(file => Path.GetFileName(file) != $"appsettings.Development.json")
.ToList()
.ForEach(file => config.AddJsonFile(file, true, true));
// Add NLogger
builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
if (!builder.Environment.IsDevelopment())