How to use NLog in C++?

删除回忆录丶 提交于 2019-12-21 12:08:28

问题


I have a simple native ++ console application in visual C++.

In order to use NLog there is a mixed mode " "NLogC.dll"

  • How can i add "NLogC.dll" to my application
  • And use for logging?

Simply how can i use Nlog in a native C++ Application?


回答1:


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.



来源:https://stackoverflow.com/questions/9077478/how-to-use-nlog-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!