technical software development

Configuring a native C++ Application to log to TraceListener


  • log4cxx-0.10.0 - download it from here

Application build requirements:

  • build the log4cxx DLL
  • add a reference to the log4cxx.lib

Application configuration

configuration through a XML configuration file:

#include <log4cxx/logger.h>
#include <log4cxx/xml/domconfigurator.h>

int main(int argc,char **argv)
  // config log4cxx with the configuration file
  log4cxx::xml::DOMConfigurator::configureAndWatch( "c:\\LogConfig.xml" );
  // Output info on the root logger
  Logger::getRootLogger()->info (_T("Hello from log4cxx."));

XML configuration file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
 <appender name="SocketAppender" class="org.apache.log4j.net.XMLSocketAppender">
  <param name="RemoteHost" value="localhost"/>
  <param name="Port" value="9000"/>
  <param name="ReconnectionDelay" value="1000"/>
  <layout class="org.apache.log4j.XMLLayout"/>
 <category name="A0123456789">
  <priority value ="info" />
  <priority value ="debug" />
  <appender-ref ref="SocketAppender" />