From C++/CLI I got a log to both console and file by:
1) Modified Project->Properties->Configuration Properties->General->
Common Language Runtime support-> /CLR
2) Copied NLog.dll from installation dir to VS Debug directory so #using can find.
3) Created NLog.config in VS Debug directory for this project:
<?xml version="1.0" ?>
<nlog xmlns="
http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console" layout="${date:format=HH\:MM\:ss} ${logger} ${message}" />
<target name="file" xsi:type="File" fileName="${basedir}/DBGfile.txt"
layout="${stacktrace} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="console,file" />
</rules>
</nlog>
I used the following test code:
#include "stdafx.h"
#using "NLog.dll" // reference the assembly. Requires C++ compilation with /clr
using namespace NLog;
ref class Program {
public:
Program(){};
~Program(){};
void doIt(){
Logger^ logger;
logger = LogManager::GetCurrentClassLogger();
logger->Debug("Hello World!");
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Program^ myProg = gcnew Program();
myProg->doIt();
return 0;
}