Skip to content

Instantly share code, notes, and snippets.

@metavige
Created October 4, 2013 08:57
Show Gist options
  • Save metavige/6823029 to your computer and use it in GitHub Desktop.
Save metavige/6823029 to your computer and use it in GitHub Desktop.
TopShelf Startup
// Start setup running service
HostFactory.New(x =>
{
x.Service<DeployMonitorService>(c =>
{
c.ConstructUsing(s => ServiceLocator.Current.GetInstance<DeployMonitorService>());
c.WhenStarted(s => s.Start());
c.WhenStopped(s => s.Stop());
c.WhenPaused(s => s.Pause());
c.WhenContinued(s => s.Resume());
});
x.RunAsLocalSystem(); // 設定成 Local System 才能寫入 Log 檔案
x.SetDescription("Window Service Description");
x.SetServiceName("WindowServiceName"); // Service 名稱不可以有空格
x.SetDisplayName("Window Service Display Title"); // 顯示名稱才可以有空格
x.StartAutomaticallyDelayed();
// x.DependsOnIis();
x.EnablePauseAndContinue();
x.EnableShutdown();
x.EnableServiceRecovery(rc =>
{
rc.RestartService(1); // restart the service after 1 minute
rc.SetResetPeriod(1);
// rc.SetResetPeriod(1); // set the reset interval to one day
});
//x.UseLog4Net();
}).Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment