I've wrote a example app below that illustrates the problem.
Any suggestions?
Kevin ( listman)

This is the exception
Unhandled exception at 0x77f5d61b in testing.exe: 0xC0000005: Access violation writing location 0x100ad678.


This is the stack
ntdll.dll!77f5d61b() ntdll.dll!77f42044() > log4cxx.dll!log4cxx::helpers::CriticalSection::lock() Line 49 + 0xc C++
log4cxx.dll!log4cxx::helpers::ObjectImpl::lock() Line 103 C++
log4cxx.dll!log4cxx::helpers::synchronized::synchronized(const log4cxx::helpers::Object * object=0x00b22d70) Line 103 + 0x24 C++
log4cxx.dll!log4cxx::FileAppender::setFile(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & fileName={...}, bool append=true, bool bufferedIO=false, int bufferSize=8192) Line 71 + 0x37 C++
log4cxx.dll!log4cxx::FileAppender::FileAppender(const log4cxx::helpers::ObjectPtrT<log4cxx::Layout> & layout={...}, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & fileName={...}) Line 54 C++
log4cxx.dll!log4cxx::RollingFileAppender::RollingFileAppender(const log4cxx::helpers::ObjectPtrT<log4cxx::Layout> & layout={...}, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & fileName={...}) Line 42 + 0xfe C++
testing.exe!main(int argc=1, char * * argv=0x00b213c8) Line 54 + 0x141 C++
testing.exe!mainCRTStartup() Line 259 + 0x19 C
kernel32.dll!77e4f38c()


This is the example code I'm trying to get to work,
Console and NTEventViewer  Appenders work great.

// testing.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <log4cxx/logger.h>
#include <log4cxx/consoleappender.h>
#include <log4cxx/patternlayout.h>
#ifdef WIN32
#include <log4cxx/nt/nteventlogappender.h>
#endif
#include <log4cxx/rollingfileappender.h>

int hello( int x )
{
 return x*x;
}
int _tmain(int argc, _TCHAR* argv[])
{
 int h = 0;
 int i = 0;
 int j = 0;
 int k = 0;
 int l = 0;
 for ( int x = 0; x < 10; x ++ )
 {
   h++;
   i++;
   j = hello( h );
 }

 log4cxx::LoggerPtr fCBLogger = NULL;
 static const char *logName = "CBLog";
 fCBLogger = log4cxx::Logger::getLogger( logName );
 if ( fCBLogger )
 {
   fCBLogger->setLevel( log4cxx::Level::DEBUG );
   static const char *layoutPattern = "%c %p %d{%Y-%b-%d %H:%M:%S} %m";

fCBLogger->addAppender( new log4cxx::ConsoleAppender( new log4cxx::PatternLayout( layoutPattern ), "system.out" ) );

if ( false )
{
fCBLogger->addAppender( new log4cxx::ConsoleAppender( new log4cxx::PatternLayout( layoutPattern ), "system.err" ) );
}


#ifdef WIN32
typedef log4cxx::helpers::ObjectPtrT<log4cxx::nt::NTEventLogAppender> NTEventLogAppenderPtr;
NTEventLogAppenderPtr ntEventLogAppender = new log4cxx::nt::NTEventLogAppender( "localhost", "Application", "cbIntegrate", new log4cxx::PatternLayout( layoutPattern ) );
ntEventLogAppender->setThreshold( log4cxx::Level::WARN );
fCBLogger->addAppender( ntEventLogAppender );
#endif


typedef log4cxx::helpers::ObjectPtrT<log4cxx::RollingFileAppender> RollingFileAppenderPtr;
RollingFileAppenderPtr rollingFileAppender = new log4cxx::RollingFileAppender( new log4cxx::PatternLayout( layoutPattern ), "cbLog.log" );
rollingFileAppender->setMaxBackupIndex( 10 );
rollingFileAppender->setMaxFileSize( "10MB" );
fCBLogger->addAppender( rollingFileAppender );
}
else
{
int k=1;
}
return 0;
}





Reply via email to