为什么我的 Topshelf 服务没有启动?
我遇到了搁置的 Topshelf 服务的问题,该服务未按预期启动:即使架子已启动文件夹更改,并且 Topshelf 注意到这一点,但服务未启动。没有显示错误消息(实际上根本没有日志消息),我真的不知道从哪里开始寻找问题。
这就是我所拥有的:
我已经在日志中验证了 Topshelf 注意到文件夹
C:\Topshelf.Host\Services\MyService\
中发生了更改。我已验证 Topshelf 架文件夹中的文件名为
MyAssembly.dll
和MyAssembly.config
。MyAssembly
和MyService
相同,甚至大小写也匹配。我的配置文件中有以下内容:
<前><代码><节名称=“log4net”类型=“log4net.Config.Log4NetConfigurationSectionHandler,log4net”/> ... 我在
MyAssembly.dll
中有以下类:命名空间 MyNamespace { 公共类 MyBootstrapper : Bootstrapper
; { 公共无效InitializeHostedService(IServiceConfigurator cfg) { cfg.HowToBuildService(name => new MyService()); cfg.WhenStarted(s => s.StartService()); cfg.WhenStopped(s => s.StopService()); } } 公共类 MyService { 公共无效StartService() { ... } 公共无效停止服务() { ... } } }
I have a problem with a shelved Topshelf service that doesn't start when it's supposed to: even though the shelf folder changes, and Topshelf notices this, the service is not started. No error messages (no log messages at all, actually) are shown, and I really don't know where to start looking for the problem.
This is what I have:
I have verified in the logs that Topshelf notices a change in the folder
C:\Topshelf.Host\Services\MyService\
.I have verified that the file names in the Topshelf shelf folder are
MyAssembly.dll
andMyAssembly.config
.MyAssembly
andMyService
are the same, matching even on case.I have the following in my configuration file:
<configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> <section name="ShelfConfiguration" type="Topshelf.Shelving.ShelfConfiguration, TopShelf" /> </configSections> <ShelfConfiguration Bootstrapper="MyNamespace.MyBootstrapper, MyAssembly" /> ...
I have the following classes in
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() { ... } } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我在问题中包含的所有内容确实设置正确,但我在配置文件的其他位置有拼写错误,这在加载我的服务时给 Topshelf 带来了麻烦。当我纠正这些错误时,一切都按预期进行。
我正在结束这个问题,因为问题并不真正在这里。
It turns out everything I included in the question was indeed correctly setup, but I had typos in other places of the config file that gave Topshelf trouble when loading my service. When I corrected those, everything worked as expected.
I'm closing the question, as the problem wasn't really here.