如何在C ++中使用NLog? [英] How to use NLog in C++?

查看:198
本文介绍了如何在C ++中使用NLog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual C ++中有一个简单的本机++控制台应用程序.

为了使用NLog,有一个混合模式" NLogC.dll"

  • 如何将"NLogC.dll"添加到我的应用程序中
  • 并用于记录吗?

请问如何在本机C ++应用程序中使用Nlog?

解决方案

NLog包括头文件(NLogC.h)和导入库(NLogC.lib).这些应该用于使用该库.

将包含文件的路径(例如C:\Program Files (x86)\NLog\.NET Framework 4.0\NLogC\include)添加到包含路径中,无论是全局的还是仅适用于项目的.您可以在配置属性","C/C ++",常规"下的其他包含目录"下的项目属性中指定它.将库文件的路径(例如C:\Program Files (x86)\NLog\.NET Framework 4.0\NLogC\x86;请确保根据要定位的体系结构选择x86或x64)添加到库路径(配置属性",链接器",常规"下的其他库目录").

NLogC.lib文件添加到项目的库中(将其添加到配置属性",链接器",输入"下的其他依赖项").

然后,您可以像这样使用API​​:

#include <cstdarg> // Needed for va_list type, which NLogC.h requires
#include <NLogC.h>

int main()
{
    NLog_Info(L"Test", L"TestMessage");

    return 0;
}

确保将NLogC.dllNLog.dll和合适的配置文件放在与可执行文件相同的目录中.

请注意,这实际上仅打算在将本机组件作为较大的托管应用程序的一部分或从本机组件过渡到托管应用程序时使用.如果您的应用程序是纯C ++,则可能会有更合适的本机日志记录库,这些库不需要仅为了进行日志记录而加载CLR.

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?

解决方案

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.

这篇关于如何在C ++中使用NLog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆