【问题标题】:Why custom command line arguments do not work when TopShelf service is installed as Win Service?为什么将 TopShelf 服务安装为 Win 服务时自定义命令行参数不起作用?
【发布时间】: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


【解决方案1】:

正如我愚蠢地问这个问题,正确的答案只能是Topshelf不支持它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2013-08-14
    • 2020-08-04
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多