I'm writing a simple Windows Service based on TopShelf. How to install my application as a service? I tried to execute SpyService.exe install
, but it doesn't work.
What is the difference between next two ways of configuring the service?
var cfg = RunnerConfigurator.New(
x =>
{
x.ConfigureService<SpyService>(s =>
{
s.Named("SpyService");
s.HowToBuildService(name => new SpyService());
s.WhenStarted(tc => {
XmlConfigurator.ConfigureAndWatch(new FileInfo(".\\log4net.config"));
tc.Start(); });
s.WhenStopped(tc => tc.Stop());
});
x.RunAsFromInteractive();
x.SetDescription("Сервис логирования действий пользователя.");
x.SetDisplayName("SpyService");
x.SetServiceName("SpyService");
});
Runner.Host(cfg, args);
and
var host = HostFactory.New(x =>
{
x.Service<SpyService>(s =>
{
s.SetServiceName("SpyService");
s.ConstructUsing(name => new SpyService());
s.WhenStarted(service =>
{
XmlConfigurator.ConfigureAndWatch(new FileInfo(".\\log4net.config"));
service.Start();
});
s.WhenStopped(service => service.Stop());
});
x.RunAsLocalSystem();
x.SetDescription("Сервис логирования действий пользователя.");
x.SetDisplayName("SpyService");
x.SetServiceName("SpyService");
});
host.Run();
I noticed that if I use the second method the service is successfully installed, but there is not possible to start the service with x.RunAsFromInteractive()
as in first way.
What version of Topshelf are you using? The old syntax was SpyService.exe service install
but has been simplified.