image
JNachbaur
technische Softwareentwicklung
Start
Screenshots Download Erste Schritte

Configuring a native C++ Application to log to TraceListener

Requirements

Application build requirements:

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"/>
	</appender>
	<category name="A0123456789">
		<priority value ="info" />
	</category>
	<root>
		<priority value ="debug" />
		<appender-ref ref="SocketAppender" />
	</root>
</log4j:configuration>