From d44d072823ca8b52610c8db2aa7af672b011c2ad Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Mon, 14 Aug 2023 21:45:00 +0200 Subject: [PATCH] config: a little dynamic config based on environmnet --- Server/Program.cs | 7 +++++++ Server/Server.csproj | 4 ++-- Server/{settings.json => settings.Development.json} | 0 3 files changed, 9 insertions(+), 2 deletions(-) rename Server/{settings.json => settings.Development.json} (100%) diff --git a/Server/Program.cs b/Server/Program.cs index a8807c3..fe92ed4 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -3,6 +3,7 @@ using System.Net; using System.Reflection; using MassTransit; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -10,6 +11,12 @@ using Server.DB; using Server.Services; var builder = Host.CreateApplicationBuilder(); +#if DEBUG +builder.Environment.EnvironmentName = "Development"; +#endif +builder.Configuration.AddJsonFile("settings.json", true, true) + .AddJsonFile($"settings.{builder.Environment.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables().Build(); builder.Services.AddLogging(); builder.Logging.AddFile("Logs/Server-{Date}.log", LogLevel.Trace); builder.Logging.AddFile("Logs/Server-{Date}.json.log", LogLevel.Trace, isJson: true); diff --git a/Server/Server.csproj b/Server/Server.csproj index 01295aa..913a9f4 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -69,8 +69,8 @@ - + PreserveNewest - + diff --git a/Server/settings.json b/Server/settings.Development.json similarity index 100% rename from Server/settings.json rename to Server/settings.Development.json