我安装在Windows serivce其获取具有通过OnStart
下面的方法来从app.config文件中某些字符串 - ConfigurationManager.AppSettings["stringName"];
里面的应用程序。配置中,我还为我用于写入日志文件的日志文件定义了一个source
。错误启动服务(服务在本地计算机上,然后自动停止)
然而,当我成功地安装我的服务,并尝试从Serivce Control Explorer
启动它里面My Computer -> Manage - > Device Manager
,我得到一个消息说
The service on the local computer and then stopped. Some services stop automatically if not used by toher applications
里面的Windows事件查看器,我收到以下错误细节(也许有在启动服务)
这里抛出的异常的为同一错误细节:
Service cannot be started. System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section add. (C:\Program Files (x86)\Default Company Name\ServiceSetup\ServiceChecker.exe.Config line 3)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Dia...
以上详细显示了与服务的.exe.config
文件相关的错误详细信息。我已尝试卸载并重新安装该服务,并将服务的安装帐户设置为Local system
,该系统具有广泛的系统要求。
我的项目App.Config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="UtilName" value="sample.exe"/>
<add key="App1" value="MyApp"/>
<add key="App1E" value="MyApp.exe"/>
<add key="App2" value="MyApp2"/>
<add key="App2E" value="MyApp2.exe" />
<add key="AppDirectory" value="Company\MyProject" />
<add key="CMDArgs" value="\start"/>
</appSettings>
<system.diagnostics>
<sources>
<source name="ServiceTrace" switchName="ServiceTraceSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="ServiceLog" type="System.Diagnostics.TextWriterTraceListener" initializeData="servicetrace.log"/>
</listeners>
</source>
</sources>
<switches>
<add name="ServiceTraceSwitch" value="Information" />
</switches>
<trace autoflush="true" indentsize="4"></trace>
</system.diagnostics>
</configuration>
请发布您的配置,似乎错误在那里。 –
@Adriano:添加了配置文件文本 – user1240679