Kiw*_*iwi 1 c# windows-services nlog
我正在做一个服务,现在是空的,只使用NLog,但是当我启动服务时,我得到以下错误;
---------------------------
Services
---------------------------
Windows could not start the JobService service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.
---------------------------
OK
---------------------------
Run Code Online (Sandbox Code Playgroud)
这是事件查看器中的堆栈跟踪:
Application: service.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Configuration.ConfigurationErrorsException
Stack:
at System.Configuration.ClientConfigurationSystem.EnsureInit(System.String)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(System.String)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)
at System.Configuration.ConfigurationManager.GetSection(System.String)
at NLog.Config.XmlLoggingConfiguration.get_AppConfig()
at NLog.LogFactory.get_Configuration()
at NLog.LogFactory.GetLogger(LoggerCacheKey)
at NLog.LogFactory.GetLogger(System.String)
at NLog.LogManager.GetLogger(System.String)
at JobsService.Service1..ctor()
Run Code Online (Sandbox Code Playgroud)
NLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<targets>
<target name="file" xsi:type="File" layout="${longdate} ${logger} ${message}" fileName="${basedir}/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
App.config在configSections中有以下行,但不知道是否需要它
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
Run Code Online (Sandbox Code Playgroud)
知道我可能错过了什么配置,或者忘了?
小智 5
我刚刚遇到同样的问题.原因是我将连接字符串放在App.Config中的配置顶部.恢复App.Config以启动configSections修复它.我不需要添加nlog-section.
从而:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<add ... />
</connectionStrings>
<!-- etcetera -->
</configuration>
Run Code Online (Sandbox Code Playgroud)
不知道为什么会这样.
注意,我在Windows服务中使用NuGet的最新NLOG(v4).
| 归档时间: |
|
| 查看次数: |
775 次 |
| 最近记录: |