Java‎ > ‎

log4j

Windows Event Logging

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.nt.NTEventLogAppender;

    private static Logger logger = Logger.getLogger(ThisClass.class);
    private void initLogger() {
        BasicConfigurator.configure();
        NTEventLogAppender eventLogAppender = new NTEventLogAppender();
        eventLogAppender.setSource("APServer");
        eventLogAppender.setLayout(new PatternLayout("%m"));
        eventLogAppender.activateOptions();
        logger.addAppender(eventLogAppender);
    }


Comments