does somebody use MDC with success? On Wed, Aug 18, 2010 at 11:27, Fabian Jacquet <fabian.jacq...@gmail.com>wrote:
> Hi all, > > I need to use NDC or MDC. I would like that child thread automatically > inherit the parent context so I try to use MDC. > > Here is my code and it seems the context is not inherited: > > #include "stdafx.h" > #include <log4cxx/log4cxx.h> > #include <log4cxx/logger.h> > #include <log4cxx/logmanager.h> > #include <log4cxx/xml/domconfigurator.h> > > DWORD WINAPI test1(LPVOID param) > { > log4cxx::LoggerPtr log = log4cxx::LogManager::getLogger("MyLogger"); > LOG4CXX_INFO(log, "Message thread with MDC"); > > return 0; > } > > int _tmain(int argc, _TCHAR* argv[]) > { > log4cxx::xml::DOMConfigurator::configure("log.xml"); > > log4cxx::LoggerPtr log = log4cxx::LogManager::getLogger("MyLogger"); > LOG4CXX_INFO(log, "Message without MDC"); > > log4cxx::MDC::put("MyMDC", "MyMDC"); > LOG4CXX_INFO(log, "Message with MDC"); > > CreateThread(NULL,NULL,test1,NULL, 0, NULL); > > Sleep(3000); > return 0; > } > > > Output: > 2010-08-18 11:27:44,015 [0x0000073c] INFO {MyLogger - ::__cdecl > wmain(24)} - Message without MDC > 2010-08-18 11:27:44,015 [0x0000073c] INFO MyMDC {MyLogger - ::__cdecl > wmain(27)} - Message with MDC > 2010-08-18 11:27:44,015 [0x00000bf0] INFO {MyLogger - ::long __stdcall > test1(14)} - Message thread with MDC > > > I don't know where is my mistake. >