你怎么调试这个错误?无法启动<service name>服务.该服务未报告错误

Lan*_*nce 8 installer windows-services

该服务无法启动.该服务未报告错误.

每当我在命令行中安装Windows服务项目时,我都会遇到此错误.确实,我的代码中存在错误,但如何通过此类错误消息找到该错误?

Ars*_*yan 9

添加服务的OnStart()方法中有一个例外

 try{...} 
 catch(Exception ex)
 {
     //write to file ex.ToString();
 }
Run Code Online (Sandbox Code Playgroud)

并将您的异常记录到文件中

  • 使用Windows事件日志... EventLog.WriteEntry(String.Format("WcfServiceHostTest \n异常消息:{0} \nTrace:{1}",ex.Message,ex.StackTrace),EventLogEntryType.Error); (3认同)