Esempio n. 1
0
        private Server CreateServer(DistributorConfig distributorConfig, ILoggerFactory loggerFactory)
        {
            if (distributorConfig == null)
            {
                throw new ApplicationException("No configuration");
            }

            if (distributorConfig.Prometheus?.IsEnabled != true)
            {
                _metricServer = null;
            }
            else
            {
                _metricServer = new MetricServer(distributorConfig.Prometheus.Port);
                _metricServer.Start();
            }

            var endPoint        = distributorConfig.ToIPEndPoint();
            var certificate     = distributorConfig.SslConfig?.ToCertificate();
            var authenticator   = distributorConfig.Authentication?.Construct <IAuthenticator>() ?? new NullAuthenticator(new string[0]);
            var distributorRole = distributorConfig.ToDistributorRole();

            var server = new Server(endPoint, authenticator, certificate, distributorRole, loggerFactory);

            server.Start(distributorConfig.HeartbeatInterval);

            return(server);
        }
Esempio n. 2
0
        public Program(string settingsFilename)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile(settingsFilename, false, true)
                                .Build();

            _distributorConfig = configuration.GetSection("distributor").Get <DistributorConfig>();

            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                .AddConfiguration(configuration.GetSection("Logging"))
                .AddDistributorLogger(_distributorConfig);
            });

            Logger = loggerFactory.CreateLogger <Program>();

            _server = CreateServer(_distributorConfig, loggerFactory);
        }
 public static ILoggingBuilder AddDistributorLogger(this ILoggingBuilder builder, DistributorConfig config)
 {
     return(config.UseJsonLogger ? builder.AddJsonConsole() : builder.AddConsole());
 }