Exemplo n.º 1
0
        public static ILoggingBuilder AddLogging(this ILoggingBuilder builder, PiraeusConfig config)
        {
            LoggerType loggerTypes = config.GetLoggerTypes();

            //if (loggerTypes.HasFlag(LoggerType.None))
            //{
            //    return builder;
            //}

            LogLevel logLevel = Enum.Parse <LogLevel>(config.LogLevel, true);


            if (loggerTypes.HasFlag(LoggerType.Console))
            {
                builder.AddConsole();
            }

            if (loggerTypes.HasFlag(LoggerType.Debug))
            {
                builder.AddDebug();
            }



            builder.SetMinimumLevel(logLevel);

            return(builder);
        }
Exemplo n.º 2
0
        private static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureLogging(builder =>
            {
                PiraeusConfig pconfig = GetPiraeusConfig();
                LogLevel logLevel = Enum.Parse <LogLevel>(pconfig.LogLevel);
                var loggers = pconfig.GetLoggerTypes();

                if (loggers.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }

                if (loggers.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }

                if (loggers.HasFlag(LoggerType.AppInsights) && !string.IsNullOrEmpty(pconfig.InstrumentationKey))
                {
                    builder.AddApplicationInsights(pconfig.InstrumentationKey);
                }

                builder.SetMinimumLevel(logLevel);
                builder.Services.AddSingleton <ILog, Logger>();
            })
                   .ConfigureWebHost(options =>
            {
                options.UseStartup <Startup>();
                options.UseKestrel();
                options.ConfigureKestrel(options =>
                {
                    PiraeusConfig config = GetPiraeusConfig();
                    options.Limits.MaxConcurrentConnections = config.MaxConnections;
                    options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
                    options.Limits.MaxRequestBodySize = config.MaxBufferSize;
                    options.Limits.MinRequestBodyDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));
                    options.Limits.MinResponseDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));

                    if (!string.IsNullOrEmpty(config.ServerCertificateFilename))
                    {
                        Console.WriteLine("Port for cert with filename");
                        options.ListenAnyIP(config.GetPorts()[0],
                                            a => a.UseHttps(config.ServerCertificateFilename, config.ServerCertificatePassword));
                    }
                    else if (!string.IsNullOrEmpty(config.ServerCertificateStore))
                    {
                        Console.WriteLine("Port for cert with store");
                        X509Certificate2 cert = config.GetServerCerticate();
                        options.ListenAnyIP(config.GetPorts()[0], a => a.UseHttps(cert));
                    }
                    else
                    {
                        Console.WriteLine("Hard coded port 8081");
                        options.ListenAnyIP(8081);
                    }
                });
            }));
        }