如何使用 Log4cxx将日志消息发送到Windows 事件日志?
如果我从多个进程中执行,它会是进程安全的吗?
好吧:谢谢退休忍者……是的,它有效……[log4j.properties 文件]
# 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
并简单地在代码中使用
#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;
}