using log4net; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; using Topshelf; namespace D7DJYMQ { class Program { private static ILog logger = LogManager.GetLogger("DS7Date"); static void Main(string[] args) { var serviceName = ConfigurationManager.AppSettings["ServiceName"]; var serviceDisplayName = ConfigurationManager.AppSettings["ServiceDisplayName"]; if (Environment.UserInteractive) { Console.Title = serviceDisplayName; } Host host = HostFactory.New(x => { // 基本的配置 x.RunAsLocalSystem(); x.SetServiceName(serviceName); x.SetDisplayName(serviceDisplayName); x.StartAutomaticallyDelayed(); x.EnableShutdown(); logger.Debug($"启动接收大简云数据接收服务"); // 注册服务 x.Service(hostSettings => new DS7Date()); logger.Debug($"注册服务"); // 设置服务失败后的操作,分别对应第一次、第二次、后续 x.EnableServiceRecovery(t => { logger.Debug($"注册服失败"); t.RestartService(0); t.RestartService(0); t.RestartService(0); t.OnCrashOnly(); //t.SetResetPeriod(1); }); }); host.Run(); } } }