/// <summary> /// 启动服务 /// </summary> /// <param name="hostControl"></param> /// <returns></returns> public bool Start(HostControl hostControl) { var config = Config.Load(); var notifyClientFactory = new NotifyClientFactory(); if (config.MailOptions != null) { notifyClientFactory.AddMailClient(config.MailOptions); } if (config.HttpOptions != null) { notifyClientFactory.AddHttpClient(config.HttpOptions); } this.context = new PlugContext { NotifyClientFactory = notifyClientFactory, LoggerFactory = new LoggerFactory().AddConsole().AddDebugger() }; this.plugs = Plugs .FindMonitorPlugs() .ToDictionary(item => item.GetType(), item => item); foreach (var item in plugs) { item.Value.OnConfigChanged += OnConfigChanged; item.Value.Start(this.context); } return(true); }
/// <summary> /// 启动插件 /// </summary> /// <param name="context">上下文</param> void IMonitorPlug.Start(PlugContext context) { var categoryName = this.GetType().Name; var logger = context.LoggerFactory.CreateLogger(categoryName); try { logger.LogInformation($"正在启动插件"); this.Context = context; this.monitorItems = this.CreateMonitorItems().ToArray(); foreach (var item in this.monitorItems) { item.OnException += OnMonitorItemException; item.Start(); } logger.LogInformation($"插件启动成功"); } catch (Exception ex) { logger.LogError(0, ex, "插件执行异常"); } }