From 96fa8781f3d42eabb4ab26d64e996d365c614838 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Thu, 29 Sep 2022 08:02:14 +1000 Subject: [PATCH] [EC-588] Add secrets override for dev logging (#2309) --- src/Core/Settings/GlobalSettings.cs | 1 + src/Core/Utilities/LoggerFactoryExtensions.cs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Core/Settings/GlobalSettings.cs b/src/Core/Settings/GlobalSettings.cs index 93a7188ca..ef80935b3 100644 --- a/src/Core/Settings/GlobalSettings.cs +++ b/src/Core/Settings/GlobalSettings.cs @@ -25,6 +25,7 @@ public class GlobalSettings : IGlobalSettings set => _logDirectory = value; } public virtual long? LogRollBySizeLimit { get; set; } + public virtual bool EnableDevLogging { get; set; } = false; public virtual string LicenseDirectory { get => BuildDirectory(_licenseDirectory, "/core/licenses"); diff --git a/src/Core/Utilities/LoggerFactoryExtensions.cs b/src/Core/Utilities/LoggerFactoryExtensions.cs index c94df3960..f6ea43882 100644 --- a/src/Core/Utilities/LoggerFactoryExtensions.cs +++ b/src/Core/Utilities/LoggerFactoryExtensions.cs @@ -20,7 +20,7 @@ public static class LoggerFactoryExtensions IHostApplicationLifetime applicationLifetime, GlobalSettings globalSettings) { - if (env.IsDevelopment()) + if (env.IsDevelopment() && !globalSettings.EnableDevLogging) { return; } @@ -33,14 +33,14 @@ public static class LoggerFactoryExtensions WebHostBuilderContext context, Func filter = null) { - if (context.HostingEnvironment.IsDevelopment()) + var globalSettings = new GlobalSettings(); + ConfigurationBinder.Bind(context.Configuration.GetSection("GlobalSettings"), globalSettings); + + if (context.HostingEnvironment.IsDevelopment() && !globalSettings.EnableDevLogging) { return builder; } - var globalSettings = new GlobalSettings(); - ConfigurationBinder.Bind(context.Configuration.GetSection("GlobalSettings"), globalSettings); - bool inclusionPredicate(LogEvent e) { if (filter == null)