I just can't make NLog to work reliably under Windows Server 2012/IIS 8. This is an Azure Virtual Machine (not a webrole) so things should have been pretty simple. Originally I had acync wrappers, database-based targets, etc. But I've stripped everything down to the bare mininum and can't seem to make it work!
This is my NLog.config file:
<?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"
>
<targets>
<target xsi:type="File"
name="nsec"
fileName="${basedir}app_data/logs/nsec_${shortdate}.log"
createDirs="true"
layout="${longdate}|${level:uppercase=true}|${logger}|${aspnet-user-identity}|${message}"
/>
</targets>
<rules>
<logger name="NSec" minlevel="Trace" writeTo="nsec"/>
</rules>
</nlog>
As you can see, there's nothing fancy here. The file target should have written to the ./App_Data/Logs directory, but most of the time nothing got written there. Sometimes something gets written to the file... And that's the most infuriating part of it all!
Locally under both Cassini and IIS Express the logs work perfectly.
Is there anything I need to add to my web.config for NLog to work? I'm not even using the ASP.NET wrapper!
Does anyone know of any incompatibility between NLog and IIS8?
UPDATE
I've run Process Monitor on the server and realized not even a single attempt is made to write, read, or query the log file. It looks as if NLog was being completely and utterly ignored. I know the NLog.config file is being read at startup because if I put an invalid configuration I get an error when accessing my application, so NLog is parsing the file. The problem is that even though it is being parsed, and sometimes something gets logged, most of the time NOTHING happens, and, as confirmed by using Process Monitor, not a single attempt is being made to access/create/write the log file.
The irony is that on Process Monitor I could see the other IIS Applications writing to their own NLog files without issues. It's only this specific application that is failing to log, but only in the production machine!