我有一个控制台应用程序,它读取SQL服务器数据,处理该数据,并将处理结果的日志记录到另一个SQL服务器表。我想使用console application
将windows service
转换为Topshelf
。
这是我的配置类:
internal static class ConfigureService
{
internal static void Configure()
{
HostFactory.Run(configure =>
{
configure.Service<MyService>(service =>
{
service.ConstructUsing(s => new MyService());
service.WhenStarted(s => s.Start());
service.WhenStopped(s => s.Stop());
});
//Setup Account that window service use to run.
configure.RunAsLocalSystem();
configure.SetServiceName("MyWindowServiceWithTopshelf");
configure.SetDisplayName("MyWindowServiceWithTopshelf");
configure.SetDescription("My .Net windows service with Topshelf");
});
}
}
和我的服务类:
public class MyService
{
public void Start()
{
Operation operation = new Operation();
operation.Zamanlayıcı();
}
public void Stop()
{
// write code here that runs when the Windows Service stops.
}
}
代码适用于控制台应用程序内的这些类。并且可以看到服务启动成功的内部控制台应用程序。但是无法在服务页面内看到该服务。这就是当安装服务时所具有的
installutil winservicebackupwork1.exe Microsoft(R).NET Framework 安装实用程序版本4.7.2046.0版权所有(C)Microsoft 公司。保留所有权利。
运行事务安装。
开始安装的安装阶段。看到的内容 的日志文件 C:----------------- WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.exe 大会的进展。该文件位于 C:----------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.InstallLog。 安装组件 'C:------------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.exe'。 受影响的参数是:logtoconsole = logfile = C:------------------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.InstallLog assemblypath = C:------------------------ \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.exe
安装阶段成功完成,提交阶段为 开始。请参阅日志文件的内容 C:--------------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.exe 大会的进展。该文件位于 C:--------------------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.InstallLog。 承诺组装 'C:-------------------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.exe'。 受影响的参数是:logtoconsole = logfile = C:---------------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.InstallLog assemblypath = C:--------------------------- \ WinServiceBackUpWork1 \ WinServiceBackUpWork1 \ BIN \调试\ winservicebackupwork1.exe
提交阶段已成功完成。
已完成交易安装。
然而根据我的研究,当我安装服务时,它应该以不同的方式打印,我不知道如何修复。
http://www.c-sharpcorner.com/article/creating-windows-service-in-net-with-topshelf/这是我的来源。请帮忙。