/// <summary>
        /// Register default Configurations from the appsettings.json which will be made available as IOptions to all services in the DI service container.
        /// </summary>
        /// <param name="services">The IServiceCollection passed into the ConfigureServices method in the Startup class.</param>
        /// <param name="configuration">The IConfiguration passed into the ConfigureServices method in the Startup class.</param>
        /// <param name="generalSettings">Returns the General settings that have been registered.</param>
        /// <param name="webApiSettings">Returns the Web API settings that have been registered.</param>
        /// <param name="httpExceptionHandlerMiddlewareSettings">Returns the HTTP Exception Handler Middler settings that have been registered.</param>
        /// <param name="webApiClientSettings">Returns the Web API Client settings that have been registered.</param>
        /// <param name="databaseSettings">Returns the Database settings that have been registered.</param>
        /// <param name="loggingSettings">Returns the Logging settings that have been registered.</param>
        /// <param name="emailSettings">Returns the Email settings that have been registered.</param>
        /// <param name="logger">Optional ILogger which if specified is used to log all the NKit settings read from the appsettings.json file.</param>
        public static void RegisterDefaultNKitSettings(
            this IServiceCollection services,
            IConfiguration configuration,
            out NKitGeneralSettings generalSettings,
            out NKitWebApiControllerSettings webApiSettings,
            out NKitHttpExceptionHandlerMiddlewareSettings httpExceptionHandlerMiddlewareSettings,
            out NKitWebApiClientSettings webApiClientSettings,
            out NKitDbContextSettings databaseSettings,
            out NKitLoggingSettings loggingSettings,
            out NKitEmailClientServiceSettings emailSettings,
            ILogger logger)
        {
            generalSettings = NKitGeneralSettings.RegisterConfiguration(configuration, services);
            webApiSettings  = NKitWebApiControllerSettings.RegisterConfiguration(configuration, services);
            httpExceptionHandlerMiddlewareSettings = NKitHttpExceptionHandlerMiddlewareSettings.RegisterConfiguration(configuration, services);
            webApiClientSettings = NKitWebApiClientSettings.RegisterConfiguration(configuration, services);
            databaseSettings     = NKitDbContextSettings.RegisterConfiguration(configuration, services);
            loggingSettings      = NKitLoggingSettings.RegisterConfiguration(configuration, services);
            emailSettings        = NKitEmailClientServiceSettings.RegisterConfiguration(configuration, services);
            if (logger == null)
            {
                return;
            }
            StringBuilder logMessage = new StringBuilder();

            logMessage.AppendLine($"*** Default NKit Settings registered from : {NKitInformation.GetAspNetCoreEnvironmentAppSettingsFileName()} ***");
            logMessage.AppendLine();

            logMessage.AppendLine($"*** {nameof(NKitGeneralSettings)} ***");
            logMessage.AppendLine(GOC.Instance.JsonSerializer.SerializeToText(generalSettings));
            logMessage.AppendLine();

            logMessage.AppendLine($"*** {nameof(NKitWebApiControllerSettings)} ***");
            logMessage.AppendLine(GOC.Instance.JsonSerializer.SerializeToText(webApiSettings));
            logMessage.AppendLine();

            logMessage.AppendLine($"*** {nameof(NKitHttpExceptionHandlerMiddlewareSettings)} ***");
            logMessage.AppendLine(GOC.Instance.JsonSerializer.SerializeToText(httpExceptionHandlerMiddlewareSettings));
            logMessage.AppendLine();

            logMessage.AppendLine($"*** {nameof(NKitDbContextSettings)} ***");
            logMessage.AppendLine(GOC.Instance.JsonSerializer.SerializeToText(databaseSettings));
            logMessage.AppendLine();

            logMessage.AppendLine($"*** {nameof(NKitLoggingSettings)} ***");
            logMessage.AppendLine(GOC.Instance.JsonSerializer.SerializeToText(loggingSettings));
            logMessage.AppendLine();

            logMessage.AppendLine($"*** {nameof(NKitEmailClientServiceSettings)} ***");
            logMessage.AppendLine(GOC.Instance.JsonSerializer.SerializeToText(emailSettings));
            logMessage.AppendLine();

            logMessage.AppendLine($"*** {nameof(NKitWebApiClientSettings)} ***");
            logMessage.AppendLine(GOC.Instance.JsonSerializer.SerializeToText(webApiClientSettings));
            logMessage.AppendLine();

            logger.LogInformation(logMessage.ToString());
        }
        /// <summary>
        /// Configures the logging providers based on the NKitLoggingSettings in the appsettings.xml file.
        /// For more information: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-5.0
        /// Logging Levels: https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel?view=dotnet-plat-ext-5.0
        /// </summary>
        public static IHostBuilder ConfigureNKitLogging(this IHostBuilder hostBuilder)
        {
            NKitLoggingSettings loggingSettings = NKitLoggingSettings.GetSettings();

            hostBuilder.ConfigureLogging(loggingBuilder =>
            {
                loggingBuilder.ClearProviders();
                loggingBuilder.AddDebug();
                loggingBuilder.AddEventSourceLogger();
                loggingBuilder.SetMinimumLevel(loggingSettings.MinimumLogLevel); //https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel?view=dotnet-plat-ext-5.0
                if (loggingSettings.LogToConsole)
                {
                    loggingBuilder.AddConsole();
                    loggingBuilder.AddNKitLogger(configuration =>
                    {
                        configuration.Color    = loggingSettings.ConsoleInformationLogEntriesColor;
                        configuration.LogLevel = LogLevel.Information;
                    });
                    loggingBuilder.AddNKitLogger(configuration =>
                    {
                        configuration.Color    = loggingSettings.ConsoleErrorLogEntriesColor;
                        configuration.LogLevel = LogLevel.Error;
                    });
                    loggingBuilder.AddNKitLogger(configuration =>
                    {
                        configuration.Color    = loggingSettings.ConsoleWarningLogEntriesColor;
                        configuration.LogLevel = LogLevel.Warning;
                    });
                    loggingBuilder.AddNKitLogger(configuration =>
                    {
                        configuration.Color    = loggingSettings.ConsoleCriticalLogEntriesColor;
                        configuration.LogLevel = LogLevel.Critical;
                    });
                    loggingBuilder.AddNKitLogger(configuration =>
                    {
                        configuration.Color    = loggingSettings.ConsoleDebugEntriesLogEntriesColor;
                        configuration.LogLevel = LogLevel.Debug;
                    });
                }
                if (loggingSettings.LogToWindowsEventLog)
                {
                    loggingBuilder.AddEventLog(new EventLogSettings()
                    {
                        LogName    = loggingSettings.EventLogName,
                        SourceName = loggingSettings.EventSourceName,
                    });
                }
            });
            return(hostBuilder);
        }
        /// <summary>
        /// Creates a LoggerFactory to create an ILogger. This method can be used to create an ILogger inside a .NET Core Startup.ConfigureServices method
        /// (where the logger has not been created since the DI container has not been created) thus allowing you to log activity that occurs inside the Startup.ConfigureServices method.
        /// </summary>
        /// <param name="categoryName">Category name for the logger to create. By convention this would typically be the name of the class that the logger is being created in.</param>
        /// <param name="loggingSettings">The IConfiguration received in the Startup class.</param>
        /// <returns></returns>
        public static ILogger CreateLogger(string categoryName, NKitLoggingSettings loggingSettings)
        {
            ILoggerFactory loggerFactory = LoggerFactory.Create(loggingBuilder =>
            {
                loggingBuilder.ClearProviders();
                loggingBuilder.AddDebug();
                loggingBuilder.AddEventSourceLogger();
                if (loggingSettings.LogToConsole)
                {
                    loggingBuilder.AddConsole();
                }
                if (loggingSettings.LogToWindowsEventLog)
                {
                    loggingBuilder.AddEventLog(new EventLogSettings()
                    {
                        LogName    = loggingSettings.EventLogName,
                        SourceName = loggingSettings.EventSourceName,
                    });
                }
            });
            ILogger result = loggerFactory.CreateLogger(categoryName);

            return(result);
        }
        /// <summary>
        /// Register default Configurations from the appsettings.json which will be made available as IOptions to all services in the DI service container.
        /// </summary>
        /// <param name="services">The IServiceCollection passed into the ConfigureServices method in the Startup class.</param>
        /// <param name="configuration">The IConfiguration passed into the ConfigureServices method in the Startup class.</param>
        /// <param name="generalSettings">Returns the General settings that have been registered.</param>
        /// <param name="webApiSettings">Returns the Web API settings that have been registered.</param>
        /// <param name="httpExceptionHandlerMiddlewareSettings">Returns the HTTP Exception Handler Middler settings that have been registered.</param>
        /// <param name="webApiClientSettings">Returns the Web API Client settings that have been registered.</param>
        /// <param name="databaseSettings">Returns the Database settings that have been registered.</param>
        /// <param name="loggingSettings">Returns the Logging settings that have been registered.</param>
        /// <param name="emailSettings">Returns the Email settings that have been registered.</param>
        /// <param name="loggerCategoryName">Optional category name of the ILogger that will be created to log the settings being registered.</param>
        public static void RegisterDefaultNKitSettings(
            this IServiceCollection services,
            IConfiguration configuration,
            out NKitGeneralSettings generalSettings,
            out NKitWebApiControllerSettings webApiSettings,
            out NKitHttpExceptionHandlerMiddlewareSettings httpExceptionHandlerMiddlewareSettings,
            out NKitWebApiClientSettings webApiClientSettings,
            out NKitDbContextSettings databaseSettings,
            out NKitLoggingSettings loggingSettings,
            out NKitEmailClientServiceSettings emailSettings,
            string loggerCategoryName)
        {
            ILogger logger = !string.IsNullOrEmpty(loggerCategoryName) ? NKitLoggingHelper.CreateLogger(loggerCategoryName, NKitLoggingSettings.GetSettings(configuration)) : null;

            RegisterDefaultNKitSettings(services, configuration,
                                        out generalSettings,
                                        out webApiSettings,
                                        out httpExceptionHandlerMiddlewareSettings,
                                        out webApiClientSettings,
                                        out databaseSettings,
                                        out loggingSettings,
                                        out emailSettings,
                                        logger);
        }