簡體   English   中英

啟動服務的NLog異常

[英]NLog exception on startup service

我正在制作一個服務,該服務現在為空,僅使用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   
---------------------------

這是事件查看器中的堆棧跟蹤:

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()

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>

App.config在configSections中具有以下行,但不知道是否需要

<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>

知道我可能錯過或忘記了什么配置嗎?

我剛剛遇到了同樣的問題。 原因是我將連接字符串放在App.Config中的配置頂部。 還原App.Config以從configSections修復它開始。 我不需要添加nlog部分。

從而:

<?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>

不知道為什么會這樣。

注意,我正在Windows服務中使用來自NuGet的最新NLOG(v4)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM