logging to a file log4j

Solutions on MaxInterview for logging to a file log4j by the best coders in the world

showing results for - "logging to a file log4j"
Melinda
30 Feb 2019
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");
similar questions
queries leading to this page
logging to a file log4j