How can i send log messages to windows event log using Log4cxx?
If i do it from multiple process , will it be process safe?
Well: Thanks Retired Ninja...Yes it works...[ log4j.properties file]
# Set root logger level to DEBUG and its only appender to EVENTLOG.
log4j.rootLogger=DEBUG, EVENTLOG
# EVENTLOG.is set to be a NTEventLogAppender
log4j.appender.EVENTLOG=org.apache.log4j.net.NTEventLogAppender
log4j.appender.EVENTLOG.server=127.0.0.1
log4j.appender.EVENTLOG.source=SomeApp
# EVENTLOG uses PatternLayout.
log4j.appender.EVENTLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.EVENTLOG.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
and simply using in the code
#include "stdafx.h"
#include <windows.h>
#include <log4cxx/logger.h>
#include "log4cxx/propertyconfigurator.h"
using namespace log4cxx;
LoggerPtr logger(Logger::getLogger( "main"));
int main()
{
PropertyConfigurator::configure("log4j.properties");
LOG4CXX_ERROR(logger, "Oh come on be serious");
system("PAUSE");
return 0;
}
I was able to do it with log4cxx version 0.10.0 a couple of years ago. I haven't used log4cxx recently, so I apologize if it has changed.
Here's the config I was using: