diff --git a/Snowflake.Data/Core/Session/EasyLoggingStarter.cs b/Snowflake.Data/Core/Session/EasyLoggingStarter.cs index d919a9ef9..01c689012 100644 --- a/Snowflake.Data/Core/Session/EasyLoggingStarter.cs +++ b/Snowflake.Data/Core/Session/EasyLoggingStarter.cs @@ -49,16 +49,17 @@ public virtual void Init(string configFilePathFromConnectionString) return; } var config = _easyLoggingConfigProvider.ProvideConfig(configFilePathFromConnectionString); + var previousInitParameters = _initParameters; if (config == null) { - _initParameters = new EasyLoggingInitParameters(configFilePathFromConnectionString, null, null); + _initParameters = EasyLoggingInitParameters.WhenConfigNotFound(configFilePathFromConnectionString); return; } var logLevel = GetLogLevel(config.CommonProps.LogLevel); - var logFilePath = GetLogPath(config.CommonProps.LogPath); - _easyLoggerManager.ReconfigureEasyLogging(logLevel, logFilePath); - _initParameters = - new EasyLoggingInitParameters(configFilePathFromConnectionString, logLevel, logFilePath); + var logPath = GetLogPath(config.CommonProps.LogPath); + WarnWhenConfigureForTheSecondTime(previousInitParameters); + _easyLoggerManager.ReconfigureEasyLogging(logLevel, logPath); + _initParameters = EasyLoggingInitParameters.WhenConfigFound(configFilePathFromConnectionString, logLevel, logPath); } } @@ -78,6 +79,18 @@ private bool TriedToInitializedWithoutConfigFileFromConnectionString() { return _initParameters != null && _initParameters.HasNoConfigFilePathFromConnectionString(); } + + private void WarnWhenConfigureForTheSecondTime(EasyLoggingInitParameters previousInitParameters) + { + if (previousInitParameters == null) + { + return; + } + if (previousInitParameters.ShouldConfigureLogger && _initParameters.ShouldConfigureLogger) + { + s_logger.Warn("Easy logging will be configured once again because it's the first time where client config is provided in a connection string"); + } + } private EasyLoggingLogLevel GetLogLevel(string logLevel) { @@ -114,14 +127,27 @@ internal class EasyLoggingInitParameters private readonly EasyLoggingLogLevel? _logLevel; private readonly string _logPath; + + public bool ShouldConfigureLogger { get; } - public EasyLoggingInitParameters(string configFilePathFromConnectionString, EasyLoggingLogLevel? logLevel, string logPath) + public EasyLoggingInitParameters( + string configFilePathFromConnectionString, + EasyLoggingLogLevel? logLevel, + string logPath, + bool shouldConfigureLogger) { _configFilePathFromConnectionString = configFilePathFromConnectionString; _logLevel = logLevel; _logPath = logPath; + ShouldConfigureLogger = shouldConfigureLogger; } + public static EasyLoggingInitParameters WhenConfigNotFound(string configFilePathFromConnectionString) => + new EasyLoggingInitParameters(configFilePathFromConnectionString, null, null, false); + + public static EasyLoggingInitParameters WhenConfigFound(string configFilePathFromConnectionString, EasyLoggingLogLevel logLevel, string logPath) => + new EasyLoggingInitParameters(configFilePathFromConnectionString, logLevel, logPath, true); + public bool HasNoConfigFilePathFromConnectionString() { return string.IsNullOrEmpty(_configFilePathFromConnectionString);