Question

I'm running into a debug logging issue with NLog, .NET 4.0.3 and Windows Server 2008 R2 (x64).

In order to view debug information that is being logged, I added an additional target and rule for debugLog to my existing NLog section of the application config file:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    throwExceptions="true">
<targets>      
  <target
    xsi:type="EventLog"
    name="eventlog"
    eventId="${event-context:EventID}"
    layout="${longdate}${logger}${newline}${message}${newline}${exception:format=ToString,StackTrace}"
    source="MyService"
    log="Application" />
  <target
    xsi:type="File"
    name="debugLog"
    fileName="c:\temp\myservice.log"
    createDirs="true"
    layout="${longdate} ${level} ${message}" />
</targets>
<rules>
  <logger
    name="*"
    minLevel="Info"
    writeTo="eventlog" />
  <logger
    name="*"
    minLevel="Debug"
    maxLevel="Deubg"
    writeTo="debugLog" />
</rules>

I ensured that the service account which runs my service has full control of the directory that I'm attempting to log to. When tested in my development environment, there are no issues - however when I try this in staging, the service fails to start and I get the following (inital) event log error with ID 1026:

Application: MyService.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.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
   at System.Configuration.BaseConfigurationRecord.GetSection(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.GetCurrentClassLogger()
   at MyService.ctor()
   at MyService.Main

There is also another error following that one in the event log with ID 1000:

Faulting application name: MyService.exe, version: 1.0.0.0, time stamp: 0x52aad29c
Faulting module name: KERNELBASE.dll, version: 6.1.7601.17651, time stamp: 0x4e211319
Exception code: 0xe0434352
Fault offset: 0x0000b9bc
Faulting process id: 0xd24
Faulting application start time: 0x01cefa5681555bf1
Faulting application path: C:\Program Files\My Service\MyService.exe
Faulting module path: C:\Windows\syswow64\KERNELBASE.dll
Report Id: c84166e5-6649-11e3-9d97-005056b33524

If I remove the debug (file) target/rule, the service starts fine.. so I'm guessing it's something obvious which I've missed in config, or maybe some security/policy related issue?

As a test, I also tried adding the service account which runs the service to the local administrators group, but this didn't resolve the problem either.

Any advice, help or suggestions would be greatly appreciated.

Thanks peteski

Was it helpful?

Solution

What a clanger, sorry all..

maxLevel="Deubg"

Should really have read Debug

/me face palms

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top