public static IWebHostBuilder AddSerilog(this IWebHostBuilder hostBuilder)
        {
            hostBuilder.ConfigureSerilog(hostingContext =>
            {
                var loggerConfiguration =
                    new LoggerConfiguration().Enrich.FromLogContext();

                if (hostingContext.HostingEnvironment.IsDevelopment())
                {
                    loggerConfiguration = loggerConfiguration
                                          .WriteTo.LiterateConsole().MinimumLevel.Debug();
                }
                else
                {
                    loggerConfiguration = loggerConfiguration
                                          .WriteTo.Graylog(new GraylogSinkOptions
                    {
                        HostnameOrAddress = hostingContext.Configuration["BE_GELF_HOST"],
                        Port     = int.Parse(hostingContext.Configuration["BE_GELF_PORT"]),
                        Facility = hostingContext.Configuration["BE_GELF_FACILITY"]
                    }).MinimumLevel.Error();
                }

                Log.Logger = loggerConfiguration.CreateLogger();
            })
            .UseSerilog();
            return(hostBuilder);
        }
        public static IWebHostBuilder AddSerilog(this IWebHostBuilder hostBuilder,
                                                 LogEventLevel prodLogEventLevel = LogEventLevel.Error, LogEventLevel devLogEventLevel = LogEventLevel.Debug)
        {
            var controller = new LogLevelController();

            hostBuilder.ConfigureSerilog(hostingContext =>
            {
                var loggerConfiguration =
                    new LoggerConfiguration().Enrich.FromLogContext();
                if (hostingContext.HostingEnvironment.IsDevelopment())
                {
                    loggerConfiguration = loggerConfiguration
                                          .WriteTo.LiterateConsole();
                    controller.Switch.MinimumLevel = devLogEventLevel;
                }
                else
                {
                    var facility = hostingContext.HostingEnvironment.ApplicationName;
                    if (!string.IsNullOrEmpty(hostingContext.Configuration["BE_GELF_FACILITY"]))
                    {
                        facility = hostingContext.Configuration["BE_GELF_FACILITY"];
                    }
                    loggerConfiguration = loggerConfiguration
                                          .WriteTo.Graylog(new GraylogSinkOptions
                    {
                        HostnameOrAddress = hostingContext.Configuration["BE_GELF_HOST"],
                        Port     = int.Parse(hostingContext.Configuration["BE_GELF_PORT"]),
                        Facility = facility
                    });
                    controller.Switch.MinimumLevel = prodLogEventLevel;
                }
                loggerConfiguration.MinimumLevel.ControlledBy(controller.Switch);
                Log.Logger = loggerConfiguration.CreateLogger();
            })
            .UseSerilog();
            hostBuilder.ConfigureServices(services =>
            {
                services.AddSingleton(controller);
                services.AddMvc().AddApplicationPart(typeof(WebHostBuilderExtensions).Assembly);
            });
            return(hostBuilder);
        }