public static ILoggerFactory ConfigureElk_v2(
            string productName            = default,
            string seqServiceUrl          = default,
            LogElkSettings logElkSettings = null)
        {
            Console.WriteLine($"App - name: {ApplicationEnvironment.AppName}");
            Console.WriteLine($"App - version: {ApplicationEnvironment.AppVersion}");

            IConfigurationRoot configRoot = BuildConfigRoot();

            var config = new LoggerConfiguration()

                         .ReadFrom.Configuration(configRoot)
                         .Enrich.FromLogContext()
                         .Enrich.With <ActivityEnricher>()
                         .Enrich.WithExceptionData()
                         .Enrich.WithCorrelationIdHeader()
                         .Destructure.UsingAttributes();

            OverrideLogLevel(config);

            SetupProperty(productName, config);

            SetupConsole(configRoot, config);

            SetupSeq(config, seqServiceUrl);

            SetupElk(logElkSettings, config);

            //Log.Logger = new SerilogSafeWrapper(config.CreateLogger());
            Log.Logger = config.CreateLogger();

            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                Log.Fatal((Exception)e.ExceptionObject, "Application has been terminated unexpectedly");
                Log.CloseAndFlush();
            };
            AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
            {
                Log.CloseAndFlush();
            };

            var factory = new LoggerFactory().AddSerilog().ToSafeLogger();

            LoggerFactoryInstance = factory;
            return(factory);
        }
        private static void SetupElk(LogElkSettings logElkSettings, LoggerConfiguration config)
        {
            if (logElkSettings?.Urls?.Any() == true && logElkSettings.Urls.All(e => !string.IsNullOrEmpty(e.Value) && e.Value != "null"))
            {
                var prefix = !string.IsNullOrEmpty(logElkSettings.IndexPrefix) ? logElkSettings.IndexPrefix : "jet-logs-def";

                var urls       = new List <Uri>();
                var httpClient = new HttpClient();
                httpClient.Timeout = TimeSpan.FromSeconds(5);

                foreach (var url in logElkSettings.Urls.Values)
                {
                    try
                    {
                        var resp = httpClient.GetAsync(url).GetAwaiter().GetResult();

                        urls.Add(new Uri(url));
                    }
                    catch (Exception ex)
                    {
                        var color = Console.ForegroundColor;
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"ELK WRONG URL: {url}. {ex.Message}");
                        Console.ForegroundColor = color;
                    }
                }

                if (!urls.Any())
                {
                    Console.WriteLine($"ElasticSearch is DISABLES");
                    return;
                }

                var option = new ElasticsearchSinkOptions(urls)
                {
                    AutoRegisterTemplate        = true,
                    EmitEventFailure            = EmitEventFailureHandling.WriteToSelfLog,
                    AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
                    TypeName     = null,
                    IndexDecider = (e, o) => $"{prefix}-{o.Date:yyyy-MM-dd}",
                    BatchAction  = ElasticOpType.Create,

                    ModifyConnectionSettings = configuration =>
                    {
                        configuration.ServerCertificateValidationCallback(CertificateValidations.AllowAll);

                        if (!string.IsNullOrEmpty(logElkSettings.User))
                        {
                            configuration.BasicAuthentication(logElkSettings.User, logElkSettings.Password);
                        }

                        return(configuration);
                    }
                };

                config.WriteTo.Elasticsearch(option);

                Console.WriteLine($"SETUP LOGGING TO ElasticSearch. Url Count: {urls.Count}. Index name: {prefix}-yyyy-MM-dd");
            }
            else
            {
                Console.WriteLine($"ElasticSearch is DISABLES");
            }
        }