///<summary> Service start method </summary> protected override void OnStart(string[] args) { // initialise logger this.Log = LogManager.GetLogger(this.ServiceName); this.Log.Info(string.Format("{0}Launching service {1}...", Environment.NewLine, this.ServiceName)); try { this.Log.Info(string.Format("Settings loading for {0}...", this.ServiceName)); // Here we take sattings form .config file NameValueCollection settingsCollection = ConfigurationManager.AppSettings; // Create new instance of common objects this.Commons = new CommonObjects(settingsCollection); this.Log.Info("Settings are loaded."); this.TokenCreator = new CancellationTokenSource(); this.WorkerTask = new Task(this.StartAction, this.TokenCreator.Token, TaskCreationOptions.LongRunning); this.WorkerTask.Start(); } catch (Exception ex) { this.Log.Error(string.Format("Error on start of service {0}: {1}.", this.ServiceName, ex)); } }
///<summary> Constructor </summary> public MainAction(CommonObjects commons) { if (commons == null) { throw new ArgumentNullException(nameof(commons)); } this.Commons = commons; this.Log = LogManager.GetLogger(nameof(MainAction)); }