using log4net; using SCADA.CommonLib.Helper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Topshelf; namespace SCADA_DAQ.Service { class ProgramMain { static void Main(string[] args) { ILog log = SCADA.CommonLib.LoggerHelper.Logger.CreatLogger(typeof(ProgramMain)); AppDomain.CurrentDomain.UnhandledException += (s, e) => { log.Error(e); }; Env.StartTick = Environment.TickCount; Env.ParameterInit(); HostFactory.Run(x => { var cfg = x.Service( s => { s.ConstructUsing(name => ServiceHost.Instance); s.WhenStarted(t => t.Start()); s.WhenPaused(t => t.Paused()); s.WhenContinued(t => t.Resume()); s.WhenStopped(t => t.Stop()); }); //x.UseLog4Net("log4net.config"); x.SetDescription("SCADA 采集"); x.SetDisplayName($"SCADA 采集 {ApplicationHelper.GetAppVersion()}"); x.SetInstanceName("SCADA_Service"); x.StartAutomatically(); // Automatic (Delayed) -- only available on .NET 4.0 or later x.RunAsLocalSystem(); x.EnableServiceRecovery((e) => { e.RestartService(0);//第一次失败执行 e.RestartService(0);//第二次失败执行 e.RestartService(0);//后续失败执行 e.OnCrashOnly(); e.SetResetPeriod(1); }); x.OnException(ex => { log.Error(ex); //异常处理 }) ; }); } } }