1 // How to log to a file using log4j :
2
3 String filePath = "D:/Logs/MyFirstLog.log";
4 PatternLayout layout = new PatternLayout("%-5p %d %m%n");
5 RollingFileAppender appender = new RollingFileAppender(layout, filePath);
6 appender.setName("MyFirstLog");
7 appender.setMaxFileSize("20MB");
8 appender.activateOptions();
9 logger.addAppender(appender);
10 logger.info("this will be printed in the provided log file");