Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何定制通用的;错误5:访问被拒绝;通过TopShelf创建的窗口服务中的错误消息_C#_Windows Services_Custom Errors_Topshelf - Fatal编程技术网

C# 如何定制通用的;错误5:访问被拒绝;通过TopShelf创建的窗口服务中的错误消息

C# 如何定制通用的;错误5:访问被拒绝;通过TopShelf创建的窗口服务中的错误消息,c#,windows-services,custom-errors,topshelf,C#,Windows Services,Custom Errors,Topshelf,我通过TopShelf创建了一个windows服务。但是,当服务在Start()期间出错时,它始终显示“错误5:访问被拒绝”对话框 我想知道是否有办法自定义代码中的错误 TopshelfExitCode exitCode = HostFactory.Run(x => { x.BeforeInstall(ApplyConfigTransform); x.AddCommandLineDefinition(DataServiceHo

我通过TopShelf创建了一个windows服务。但是,当服务在Start()期间出错时,它始终显示“错误5:访问被拒绝”对话框

我想知道是否有办法自定义代码中的错误

TopshelfExitCode exitCode = HostFactory.Run(x =>
        {
            x.BeforeInstall(ApplyConfigTransform);
            x.AddCommandLineDefinition(DataServiceHost.ANONYMIZE_NAMES, s => options.Add(DataServiceHost.ANONYMIZE_NAMES, s));
            x.AddCommandLineDefinition(DataServiceHost.PORT_OVERRIDE, s => options.Add(DataServiceHost.PORT_OVERRIDE, s));
            x.Service<DataServiceHost>(s =>
            {
                s.ConstructUsing(name => new DataServiceHost());
                s.WhenStarted(host => host.Start(options));
                s.WhenStopped(host => host.Stop());
                s.WhenShutdown(host => host.LogEvent("Shutdown"));
                s.WhenPaused(host => host.LogEvent("Paused"));
                s.WhenContinued(host => host.LogEvent("Continued"));
                s.WhenSessionChanged((host, scArgs) => host.LogSessionChanged(scArgs));
            });
            x.SetServiceName("service name");
            x.SetDisplayName("service name");
            x.SetDescription("service desc");

            x.EnableServiceRecovery(rc =>
            {
                rc.RestartService(1); // restart the service after 1 minute
                rc.SetResetPeriod(1); // set the reset interval to one day
            });

            x.RunAsLocalSystem();
        });
TopshelfExitCode exitCode=HostFactory.Run(x=>
{
x、 安装前(应用配置转换);
x、 AddCommandLineDefinition(DataServiceHost.ANONYMIZE_NAMES,s=>options.Add(DataServiceHost.ANONYMIZE_NAMES,s));
x、 AddCommandLineDefinition(DataServiceHost.PORT_OVERRIDE,s=>options.Add(DataServiceHost.PORT_OVERRIDE,s));
x、 服务(s=>
{
s、 ConstructUsing(name=>newDataServiceHost());
s、 开始时(host=>host.Start(选项));
s、 停止时(host=>host.Stop());
s、 停机时(host=>host.LogEvent(“停机”);
s、 使用时(host=>host.LogEvent(“暂停”);
s、 当继续时(host=>host.LogEvent(“Continued”);
s、 当会话更改时((主机,scArgs)=>host.LogSessionChanged(scArgs));
});
x、 SetServiceName(“服务名称”);
x、 SetDisplayName(“服务名称”);
x、 SetDescription(“服务描述”);
x、 启用ServiceRecovery(rc=>
{
rc.RestartService(1);//1分钟后重新启动服务
rc.SetResetPeriod(1);//将重置间隔设置为一天
});
x、 RunAsLocalSystem();
});