【发布时间】:2014-11-23 18:26:09
【问题描述】:
它们可以完美地用作控制台应用程序。我就是这样做的:
private static int Main()
{
string databaseName = null;
string databaseUser = null;
string databasePwd = null;
string port = null;
string logDirectory = null;
string strLogLevel = null;
var exitCode = HostFactory.Run(configurator =>
{
configurator.AddCommandLineDefinition("dbname", d => { databaseName = d; });
configurator.AddCommandLineDefinition("dbuser", d => { databaseUser = d; });
configurator.AddCommandLineDefinition("dbpassword", d => { databasePwd = d; });
configurator.AddCommandLineDefinition("port", p => { port = p; });
configurator.AddCommandLineDefinition("logdirectory", l => { logDirectory = l; });
configurator.AddCommandLineDefinition("loglevel", l => { strLogLevel = l; });
configurator.ApplyCommandLine();
int intPort = 7909;
if (port != null)
intPort = Convert.ToInt32(port);
SystemDataApplication.LogLevel logLevel = SystemDataApplication.LogLevel.Info;
if (strLogLevel != null)
logLevel = (SystemDataApplication.LogLevel)Convert.ToInt32(strLogLevel);
configurator.Service<SystemDataApplication>(service =>
{
service.ConstructUsing(() => new SystemDataApplication(databaseName, databaseUser, databasePwd, intPort, logDirectory, logLevel));
service.WhenStarted(a => a.Start());
service.WhenStopped(a => a.Stop());
});
configurator.SetDescription("An application to fetch system data.");
configurator.SetDisplayName("System Data Service");
configurator.SetServiceName("SystemDataService");
configurator.RunAsNetworkService();
});
return (int)exitCode;
}
作为控制台应用程序,它会在跟踪日志中打印所有这些都可以。如果我安装它(命令中的所有自定义参数)并从命令行启动它(命令中的所有自定义参数),它们在跟踪日志中为空。
【问题讨论】:
-
好吧,似乎他们从来没有因为一些非常奇怪的原因。如果编写普通的控制台应用程序,谁想使用 Topshelf。我再也不会使用它了。
标签: asp.net-web-api owin self-hosting topshelf