I'm using NLog library for logging purposes.
I have declared the following class:
public partial class FenetrePrincipale : Form
{
#region NLog
private static readonly Logger logger = LogManager.GetLogger("FenetrePrincipale");
#endregion
...
I run over the following lines of source code:
private bool StartService()
{
try
{
logger.Debug("Try to start service");
My NLog.config looks as follows:
<?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">
<targets>
<target name="file"
xsi:type="File"
fileName="${basedir}/${date:format=yyyyMMdd}.log"
layout="${longdate} | ${level:uppercase=true} | ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
... but no logfile gets created, although I'm sure i'm in the right directory (check the PID in Visual Studio, look for that in Windows Task Manager, and choose "Open file location" in the context menu).
Is there a way to alter logger.Debug(text); into logger.Debug(text,explanation) where the explanation is filled in by NLog and tells me why no logfile is created? (I don't believe this exists: I have decompiled NLog and I didn't find Debug(..., out ...))
Is there another way to find out what's going wrong?
For your information: it has worked before in that directory, it's certainly not a problem with file permissions or so.
Edit:
As proposed by Fildor, I have modified my nlog.config file as follows:
<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"
internalLogFile="c:\Temp_Folder\log.txt" internalLogLevel="Trace">
... but no result:
Command prompt>dir c:\Temp_Folder\log.txt
...
Directory of c:\Temp_Folder
File Not Found
However, my NLog.dll seems recent enough:
... and the mentioned GitHub URL mentions quite regularly "introduced with NLog 4.3".
As far as NLog in my solution is concerned, this is what the solution looks like:
Is there a link with this eventlog?
In the Windows event log, "Windows Logs.System", there is following entry:
The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID {2593F8B9-4EAF-457C-B68A-50F6B8EA6B54} and APPID {15C20B67-12E7-4BB6-92BB-7AFF07997402} to the user DOMAIN\DDM SID (S-1-5-21-1049629045-689772303-932725714-51094) from address LocalHost (Using LRPC) running in the application container Unavailable SID (Unavailable). This security permission can be modified using the Component Services administrative tool.
Edit about adding 'NLog.config' to the Visual Studio solution:
Although I didn't believe in the sense of adding NLog.config to the Visual Solution file, I did it anyway:

This, however, did not make any difference: the logfile still does not get created, neither did the internal logfile (C:\Temp_Folder\Log.txt).


NLogis taking mynlog.configfile into account? As mentioned, it's located in the same directory as my application.NLog.config-file. Again I suggest enabling the NLog InternalLogger from code to see why it cannot load theNLog.config-file.