I have a simple native ++ console application in visual C++.
In order to use NLog there is a mixed mode " "NLogC.dll"
Simply how can i use Nlog in a native C++ Application?
Configuration in C# using NLog; using NLog. Config; using NLog. Targets; ... var config = new LoggingConfiguration(); var consoleTarget = new ConsoleTarget { Name = "console", Layout = "${longdate}|${level:uppercase=true}|${logger}|${message}", }; config.
Writing Log Messages With NLog The available methods for logging are (in ascending order): Trace, Debug, Info, Warn, Error, and Fatal. Each of these methods creates a log message with a corresponding log level—an indicator of the message's importance.
NLog includes a header file (NLogC.h
) and import library (NLogC.lib
). Those should be used to use the library.
Add the path to the include file (e.g. C:\Program Files (x86)\NLog\.NET Framework 4.0\NLogC\include
) to the include path, either globally or for the project only. You can specify it in the project's properties under "Additional Include Directories" under Configuration Properties, C/C++, General. Add the path to the library file (e.g. C:\Program Files (x86)\NLog\.NET Framework 4.0\NLogC\x86
; make sure to pick x86 or x64 based on the architecture you're targeting) to the library path ("Additional Library Directories" under Configuration Properties, Linker, General).
Add the NLogC.lib
file to the project's libraries (add it to "Additional Dependencies" under Configuration Properties, Linker, Input).
Then, you can use the API like this:
#include <cstdarg> // Needed for va_list type, which NLogC.h requires
#include <NLogC.h>
int main()
{
NLog_Info(L"Test", L"TestMessage");
return 0;
}
Make sure you put NLogC.dll
, NLog.dll
, and a suitable configuration file in the same directory as your executable.
Note that this is really only intended to be used when you have native components as part of a larger, managed application, or are transitioning from native to managed. If your application is pure C++, there are likely more suitable native logging libraries that don't require loading the CLR just to do logging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With