I want to log to different files in my code.
How can i do that in Log4cxx with xml configuration or programatically in code...
Update:
Logger.addAppender() approach:
log4cxx::helpers::Pool p;
std::string paramAppender = "appxNormalAppender";
std::string paramFileName = "\\Logs\\MyLog.txt";
LOG4CXX_DECODE_CHAR(logAppender, paramAppender );
LOG4CXX_DECODE_CHAR(logFileName, paramFileName );
FileAppenderPtr fileAppender =
logger->getLoggerRepository()->getRootLogger()->getAppender(logAppender);
if(fileAppender!= NULL)
{
fileAppender->setFile(logFileName);
fileAppender->activateOptions(p);
}
This does not work because
Suppose that i set FileName to Logger-k for k component, it logs to Logger-k, then i set file name to Logger-k+1 for compoent k+1, then both component k, and k+1 log the same loggerk+1 file. It seems last file name overrides or effects all others...
And
All compoenent compenent 1, ...compoeent k, componentk+1,.... component n are in the same application...
Create Each of the Loggers as normal, and then for each logger add a FileAppender set to the desired file via the Logger.addAppender() method.