static void Main(string[] args) { var serverName = EnvManager.FindArgumentValue("server"); var configPathes = EnvManager.FindArgumentValues("config"); if (string.IsNullOrEmpty(serverName) || (configPathes.Count < 1)) { Console.WriteLine("You need to provide serverName and at least one config path!"); Console.WriteLine("Closing..."); Console.ReadKey(); return; } var loggerFactory = new LoggerFactory(); if (EnvManager.HasArgument("-console-log")) { loggerFactory.AddConsole(CustomLogFilter); } loggerFactory.AddFile("log.txt", false); var messageFormat = MessageFormat.LastTaskFailMessage; var consoleService = new ConsoleService(loggerFactory, messageFormat); var services = new List <IService> { consoleService, new SlackService(loggerFactory, messageFormat), new StatService("stats.xml", loggerFactory, true) }; services.TryAddNotificationService(loggerFactory); var commandFactory = new CommandFactory(loggerFactory); var server = new BuildServer(commandFactory, loggerFactory, serverName); string startUpError = null; if (!server.TryInitialize(out startUpError, services, configPathes)) { Console.WriteLine(startUpError); Console.WriteLine("Closing..."); Console.ReadKey(); return; } Console.WriteLine($"{server.ServiceName} started and ready to use."); consoleService.Process(); }
public static void TryAddNotificationService(this List <IService> services, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger("ServicesExtensions"); var notifyValue = EnvManager.FindArgumentValue("notify"); if (notifyValue != null) { logger.LogDebug($"TryAddNotificationService: Found notify arg value: '{notifyValue}'"); if (Utils.TryParseTimeSpan(notifyValue, out TimeSpan span)) { logger.LogDebug($"TryAddNotificationService: Parsed TimeSpan: '{span}'"); var service = new NotificationService(loggerFactory, span); services.Add(service); return; } } logger.LogDebug("TryAddNotificationService: Notify arg isn't found."); }