public static ILogger InitializeAppLogging(
            [NotNull] MultiSourceKeyValueConfiguration multiSourceKeyValueConfiguration,
            ILogger logger,
            IEnumerable <ILoggerConfigurationHandler> loggerConfigurationHandlers,
            LoggingLevelSwitch loggingLevelSwitch,
            SerilogConfiguration?serilogConfiguration = null,
            string?applicationName = null)
        {
            if (multiSourceKeyValueConfiguration is null)
            {
                throw new ArgumentNullException(nameof(multiSourceKeyValueConfiguration));
            }

            logger.Verbose("Getting Serilog configuration");

            var serilogConfigurations = multiSourceKeyValueConfiguration.GetInstances <SerilogConfiguration>();

            if (serilogConfigurations.Length > 1)
            {
                logger.Warning("Found multiple Serilog configurations {Configurations}", serilogConfigurations);
            }

            if (serilogConfiguration is { })
        public static ILogger InitializeAppLogging(
            [NotNull] MultiSourceKeyValueConfiguration multiSourceKeyValueConfiguration,
            ILogger logger,
            Action <LoggerConfiguration> loggerConfigurationAction, LoggingLevelSwitch loggingLevelSwitch)
        {
            if (multiSourceKeyValueConfiguration == null)
            {
                throw new ArgumentNullException(nameof(multiSourceKeyValueConfiguration));
            }

            SerilogConfiguration serilogConfiguration =
                multiSourceKeyValueConfiguration.GetInstances <SerilogConfiguration>().FirstOrDefault();

            if (!serilogConfiguration.HasValue())
            {
                logger.Error("Could not get any instance of type {Type}", typeof(SerilogConfiguration));
                return(logger);
            }

            if (serilogConfiguration.RollingLogFilePathEnabled && !serilogConfiguration.RollingLogFilePath.HasValue())
            {
                const string message = "Serilog rolling file log path is not set";
                logger.Error(message);
                throw new DeployerAppException(message);
            }

            LoggerConfiguration loggerConfiguration = new LoggerConfiguration()
                                                      .MinimumLevel.ControlledBy(loggingLevelSwitch)
                                                      .Enrich.WithProperty("Application", ApplicationConstants.ApplicationName);

            if (serilogConfiguration.DebugConsoleEnabled)
            {
                loggerConfiguration = loggerConfiguration.WriteTo.Debug();
            }

            if (serilogConfiguration.SeqEnabled && serilogConfiguration.IsValid)
            {
                if (!string.IsNullOrWhiteSpace(serilogConfiguration.SeqUrl) &&
                    Uri.TryCreate(serilogConfiguration.SeqUrl, UriKind.Absolute, out Uri serilogUrl))
                {
                    logger.Debug("Serilog configured to use Seq with URL {Url}", serilogUrl.AbsoluteUri);
                    loggerConfiguration = loggerConfiguration.WriteTo.Seq(serilogUrl.AbsoluteUri);
                }
            }

            if (serilogConfiguration.RollingLogFilePathEnabled)
            {
                string logFilePath = Path.IsPathRooted(serilogConfiguration.RollingLogFilePath)
                    ? serilogConfiguration.RollingLogFilePath
                    : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, serilogConfiguration.RollingLogFilePath);

                var fileInfo = new FileInfo(logFilePath);

                if (fileInfo.Directory != null)
                {
                    string rollingLoggingFile = Path.Combine(fileInfo.Directory.FullName,
                                                             $"{Path.GetFileNameWithoutExtension(fileInfo.Name)}.{{Date}}{Path.GetExtension(fileInfo.Name)}");

                    logger.Debug("Serilog configured to use rolling file with file path {LogFilePath}",
                                 rollingLoggingFile);

                    loggerConfiguration = loggerConfiguration
                                          .WriteTo.File(rollingLoggingFile);
                }
            }

            loggerConfiguration = loggerConfiguration.WriteTo.Console();

            LoggerConfiguration finalConfiguration = loggerConfiguration
                                                     .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                                                     .Enrich.FromLogContext();

            loggerConfigurationAction?.Invoke(loggerConfiguration);

            Logger appLogger = finalConfiguration
                               .CreateLogger();

            appLogger.Debug("Initialized app logging");

            return(appLogger);
        }