Hi guys,
The head revision builds and the dll works for VS.Net 2003. The problem was
dumb. My application was loading an older log4cxxd.dll from a different path
(aaargh) and hence the linker and runtime errors popped up as the lib file
did not match the dll. It's just not your day (or days) sometimes. :)
But now that I have it working I have some issues:
1) OutputDebugAppender has a bug. If you do not specify a layout pointer it
crashes at runtime. The following code WORKS in case someone wants to try
it.
------------------------- Working Code -----------------------------------
log4cxx::LoggerPtr LoggerMain(log4cxx::Logger::getLogger("LoggingMain"));
log4cxx::LogString logPatStrMain = (log4cxx::logchar*) L"%d [%t] %l %p -
%m%n";
//Create the pattern layout using the string used above
log4cxx::PatternLayoutPtr PatLayoutMain = new
log4cxx::PatternLayout(logPatStrMain);
//Add the OutputDebugString Appender to the Main Logger
log4cxx::nt::OutputDebugStringAppender* pTestODA = new
log4cxx::nt::OutputDebugStringAppender();
pTestODA->setLayout(PatLayoutMain);
LoggerMain->addAppender(pTestODA);
---------------------------------------------------------------------------
BUT if you remove pTestODA->setLayout(PatLayoutMain); then you will see that
the program crashes.
The cause of the crash is the line layout->format(buf, event, p); in the
append function located in outputdebugstringappender.cpp.
If buf is null it crashes.
void OutputDebugStringAppender::append(const spi::LoggingEventPtr& event,
Pool& p)
{
LogString buf;
layout->format(buf, event, p);
#if LOG4CXX_HAS_WCHAR_T
LOG4CXX_ENCODE_WCHAR(wstr, buf);
::OutputDebugStringW(wstr.c_str());
#else
LOG4CXX_ENCODE_CHAR(str, buf);
::OutputDebugStringA(str.c_str());
#endif
}
#endif
2) Hey Curt / Andreas even after building the dll with -Dhas.wchar_t=1, I
still see the raw Unicode strings in the console and ?????? in the text
file. Can you guys point me in the correct direction for testing
multi-lingual string logging with log4cxx.
Thanks
Arun