static void Main(string[] args) { TopshelfExitCode exitCode = TopshelfExitCode.Ok; try { // https://github.com/serilog/serilog/wiki/AppSettings Log.Logger = new LoggerConfiguration() .ReadFrom.AppSettings() .CreateLogger(); Log.Information("*** Begin Application. ***"); exitCode = HostFactory.Run(x => { var settings = new LoggerJsonSettings().Load(); Log.Information("Loaded settings at {0}", settings.DefaultPath); x.Service <LoggerService>(s => { s.ConstructUsing(name => new LoggerService(settings)); s.WhenStarted(tc => tc.Start()); s.WhenStopped(tc => tc.Stop()); }); x.EnableServiceRecovery(r => { r.OnCrashOnly(); r.RestartService(1); //first r.RestartService(1); //second r.RestartService(1); //subsequents }); //Windowsサービスの設定 x.RunAs(settings.LoggerSettings.ServiceUserName, settings.LoggerSettings.ServicePassword); x.SetDescription(loggerConstants.ServiceDescription); x.SetDisplayName(loggerConstants.ServiceDsiplayName); x.SetServiceName(loggerConstants.ServiceServiceName); x.StartAutomaticallyDelayed(); }); } catch (Exception ex) { Log.Error(ex, "Topshelf down?"); } finally { Log.Information("*** Topshelf exit code is {0} ***", exitCode); Log.CloseAndFlush(); } }
private bool disposedValue = false; // 重複する呼び出しを検出するには protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { Settings = null; CancellationTokenSource = null; PlcWatchers = null; RecipeWatcher = null; DbConsumer = null; } // アンマネージ リソース (アンマネージ オブジェクト) を解放し、下のファイナライザーをオーバーライドします。 // 大きなフィールドを null に設定します。 disposedValue = true; } }
public LoggerService(LoggerJsonSettings settings) { Settings = settings; }