Kiwi
Kiwi

Reputation: 2773

NLog exception on startup service

I'm making a service, that is for now empty and only NLog is used, but when I start the service I get the following error;

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

this is the stack trace in the event viewer:

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 has the following line in the configSections, but don't know if it's needed

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

Any idea what config I might have missed, or forgot?

Upvotes: 1

Views: 1144

Answers (1)

jan-marten
jan-marten

Reputation: 76

I've just came across the same issue. Reason was that I put the connectionstrings at top of the configuration in App.Config. Reverting the App.Config to start with the configSections fixed it. I didn't need the nlog-section added.

Thus:

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

Not sure why this is happening.

Note, I am using the latest NLOG (v4) from NuGet in a Windows Service.

Upvotes: 5

Related Questions