static void Run(string config, UInt16 prometheusPort = 8080, bool noPrometheus = false, bool noConsole = false) { var rawConfig = RawConfig.Create(config); var configObj = Config.Create(rawConfig); var netInfo = NetworkHelpers.PrimaryNetUpdates; var usePrometheus = !noPrometheus; if (usePrometheus) { PrometheusPublisher.StartMetrics(prometheusPort); System.Console.WriteLine($"Prometheus endpoint listening on port {prometheusPort}"); } var vizSubscription = InitMetricsAndViz(configObj, netInfo, usePrometheus, noConsole); NetworkHelpers.AddressChanged.Subscribe(_ => { if (vizSubscription != null) { vizSubscription.Dispose(); } vizSubscription = InitMetricsAndViz(configObj, netInfo, usePrometheus, noConsole); }); if (noPrometheus && noConsole) { System.Console.WriteLine("Warning: Checks are being performed, but both console visualization and prometheus endpoint are disabled!"); System.Console.WriteLine(" This is a pointless waste of CPU and bandwidth."); } Thread.Sleep(Timeout.Infinite); }
private Logger CreateLogger() { lock (syncRoot) { string outputTemplate = GetConfigValue("outputTemplate", RawConfig.GetChildren()); string filterExpression = GetConfigValue("expression", RawConfig.GetChildren()); string pathFormat = GetConfigValue("pathFormat", RawConfig.GetChildren()); logsPath = Path.GetDirectoryName(pathFormat); writerStringBuilder = new StringBuilder(); writer = new StringWriter(writerStringBuilder); return(new LoggerConfiguration() .ReadFrom.ConfigurationSection(RawConfig) .WriteTo.Logger(config => config.WriteTo.Memory(writer, LogEventLevel.Information, outputTemplate).Filter.ByIncludingOnly(filterExpression)) .CreateLogger()); } }