diff --git a/MobileConfiguration/MobileConfiguration.csproj b/MobileConfiguration/MobileConfiguration.csproj index 531b2ac..73c1d34 100644 --- a/MobileConfiguration/MobileConfiguration.csproj +++ b/MobileConfiguration/MobileConfiguration.csproj @@ -65,9 +65,9 @@ - - - + + + diff --git a/MobileConfiguration/Program.cs b/MobileConfiguration/Program.cs index af57c19..94436ea 100644 --- a/MobileConfiguration/Program.cs +++ b/MobileConfiguration/Program.cs @@ -82,9 +82,9 @@ builder.Services.AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("ConfigurationDatabase"))); } -bool logRequests = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "LogRequests", true); -bool logResponses = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "LogResponses", true); -LogLevel middlewareLogLevel = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning); +bool logRequests = ConfigurationReader.GetValueOrDefault("MiddlewareLogging", "LogRequests", true); +bool logResponses = ConfigurationReader.GetValueOrDefault("MiddlewareLogging", "LogResponses", true); +LogLevel middlewareLogLevel = ConfigurationReader.GetValueOrDefault("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning); RequestResponseMiddlewareLoggingConfig config = new(middlewareLogLevel, logRequests, logResponses); @@ -132,23 +132,4 @@ async Task InitializeDatabase(IApplicationBuilder app) await dbContext.MigrateAsync(CancellationToken.None); } } -} - -public static class ConfigurationReaderExtensions { - public static T GetValueOrDefault(String sectionName, - String keyName, - T defaultValue) { - try { - var value = ConfigurationReader.GetValue(sectionName, keyName); - - if (String.IsNullOrEmpty(value)) { - return defaultValue; - } - - return (T)Convert.ChangeType(value, typeof(T)); - } - catch (KeyNotFoundException kex) { - return defaultValue; - } - } } \ No newline at end of file