I am still trying to learn about log4cxx and once again, I stumbled over
a little pitfall.

Using the LOG4CXX_TRACE macro results in a linker error. The linker
can't find the symbol
log4cxx::Logger::isTraceEnabled(void)const

> main.obj : error LNK2019: unresolved external symbol 
> ""public: bool __thiscall log4cxx::Logger::isTraceEnabled(void)const "

> ([EMAIL PROTECTED]@log4cxx@@QBE_NXZ)" in function "_main".
> C:\Project\test-logging.exe : 
> fatal error LNK1120: 1 unresolved external symbol.

This is a simple demo program.

01 #include <iostream>
02 #include <log4cxx/logger.h>
03 #include <log4cxx/basicconfigurator.h>
04 #include <log4cxx/helpers/exception.h>
05
06 int main(int argc, char **argv)
07 {
08   try {
09     std::cout << "Test Logging ...\n";
10
11     log4cxx::BasicConfigurator::configure();
12
13     log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("MyApp"));
14     LOG4CXX_TRACE(logger, "Some logging message.");
15   }
16   catch (log4cxx::helpers::Exception &e) {
17     std::cout << "log4cxx exception: " << e.what() << "!\n";
18   }
19   catch (...) {
20     std::cout << "unknown exception!\n";
21   }
22
23   return 0;
24 }

Replacing line 14 with
14     LOG4CXX_DEBUG(logger, "Some logging message."); 
works fine.

This example program was linked with the debug/static version of
Log4Cxx.

Linking the program with the release/static version results in a program
crash.
No exception is caught. The operating system shows the following error
message:
"The exception unknown software exception (0xc0000409) occurred in the 
application at location 0x00504226."

Is it recommended to use the release build? Or should I only use a debug
build?

By the way: I am using a log4cxx current snapshot (this afternoon) on
Windows XP
with MS Visual Studio 2005.

Regards,

  Torsten

Reply via email to