Logger :: getInstance导致log4cplus中的bad_alloc异常 [英] Logger::getInstance causing bad_alloc exception in log4cplus

查看:961
本文介绍了Logger :: getInstance导致log4cplus中的bad_alloc异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在使用log4cplus的c ++应用程序中实现日志记录。我可以成功地构建/链接(我添加了log4cplus.lib到我的额外的libs和复制log4cplus.dll到build / outdir)

I'm attempting to implement logging in a c++ application using log4cplus. I'm able to successfully build/link (I added the log4cplus.lib to my additional libs and copied the log4cplus.dll to the build/outdir)

当我运行我的应用程序,当它执行我的Logger :: getInstance调用时,得到以下异常:

When I run my application, I get the following exception when it executes my Logger::getInstance call:

在LogTesterConsole.exe中的0x75cad36f未处理的异常:Microsoft C ++异常:std :: bad_alloc在内存位置0x0013ed8c ..

Unhandled exception at 0x75cad36f in LogTesterConsole.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0013ed8c..

我试过将调用放在我的main()例程以外和里面,并得到相同的结果。

I've tried placing the call outside my main() routine as well as inside and have the same results.

有任何想法?

代码: -

 #include "stdafx.h"
 #include <log4cplus/logger.h>
 #include <log4cplus/loggingmacros.h>
 #include <log4cplus/configurator.h>
 using namespace log4cplus;
 int _tmain(int argc, _TCHAR* argv[])
 { 
   BasicConfigurator config;
   config.configure();
   Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
   LOG4CPLUS_WARN(logger, LOG4CPLUS_TEXT("Hello, World!"));
   return 0;
 }


推荐答案

应用程序在调试时,一定要链接到lib4CplusD.lib和lib4CplusD.dll。同样,发布应用程序应该链接aginst lib4cplus.lib和lib4cplus.dll我有相同的运行时错误,当我链接我的调试应用程序对调试库,问题解决。

If you're building your application in debug, be sure to link to lib4CplusD.lib and lib4CplusD.dll. Likewise, a release application should link aginst lib4cplus.lib and lib4cplus.dll I had the same runtime error, and when I linked my debug application against the debug libraries, the problem was resolved.

这篇关于Logger :: getInstance导致log4cplus中的bad_alloc异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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