5

I'm using log4cplus library and I can't get logging to work.

I use this code:

PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log.properties"));
Logger g_logger = Logger::getInstance(LOG4CPLUS_TEXT("mylogger"));

LOG4CPLUS_WARN(g_logger, LOG4CPLUS_TEXT("test test test"));

And it breaks at LOG4CPLUS_WARN with error: Access violation reading location

This is my Call Stack:

msvcp110d.dll!std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >::egptr() Line 236    C++
ProjectClientd.exe!std::basic_stringbuf<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::str() Line 103 C++
ProjectClientd.exe!std::basic_ostringstream<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::str() Line 553 C++
>   ProjectClientd.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 55    C++
ProjectClientd.exe!__tmainCRTStartup() Line 528 C
ProjectClientd.exe!wWinMainCRTStartup() Line 377    C

where wWinMain ... line 55 is a place where LOG4CPLUS_WARN is being called.

I have checked what's wrong with this basic_ostringstream and it seems that something is messed up with encoding or something: enter image description here

Non-terminated string (unreadable memory) and a whole bunch of strange letters at the end of my string? What may cause it?

Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65

1 Answers1

1

Have you solved your problem? I have the same error, and I've noticed, that I linked with release version of log4cplusU.dll while application was built in debug, so linkage with log4cplusUD.dll for debug configuration solved my issue

yudjin
  • 349
  • 5
  • 14
  • Unfortunaltey I haven't yet solved my problem. I finally used GLOG library instead of log4cplus. Anyway, I've already checked the solution you gave, I think I found it somewhere else also. But I was using the right dlls, so that was not a reason in my case. – Piotr Chojnacki Sep 26 '13 at 13:53