我有一个搁置的Topshelf服务在它应该启动的时候没有启动的问题:即使货架文件夹发生了变化,并且 Topshelf 注意到了这一点,该服务也没有启动。没有显示错误消息(实际上根本没有日志消息),我真的不知道从哪里开始寻找问题。
这就是我所拥有的:
我在日志中验证了 Topshelf 注意到文件夹中的更改
C:\Topshelf.Host\Services\MyService\
。我已验证 Topshelf 架子文件夹中的文件名是
MyAssembly.dll
和MyAssembly.config
.MyAssembly
并且MyService
是相同的,即使在大小写上也匹配。我的配置文件中有以下内容:
<configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> <section name="ShelfConfiguration" type="Topshelf.Shelving.ShelfConfiguration, TopShelf" /> </configSections> <ShelfConfiguration Bootstrapper="MyNamespace.MyBootstrapper, MyAssembly" /> ...
我有以下课程
MyAssembly.dll
:namespace MyNamespace { public class MyBootstrapper : Bootstrapper<MyService> { public void InitializeHostedService(IServiceConfigurator<MyService> cfg) { cfg.HowToBuildService(name => new MyService()); cfg.WhenStarted(s => s.StartService()); cfg.WhenStopped(s => s.StopService()); } } public class MyService { public void StartService() { ... } public void StopService() { ... } } }