2 Minutes To Code (β Version)

Log4j - 2 minute tutorial

How to make log files rotate based on size using log4j.properties

This log4j.properties file will create a log file named example.log in the folder d:/logs. If this file exceeds a size of 100KB, it will be renamed to example.log.1 and a replaced by a new example.log file. A maximum of 5 such backup files will be created.

If you are using log4j-1.2.11 or earlier, then you will need to create the folder d:/logs yourself, else log4j will fail to create the log file. In later versions, log4j creates it for you.

To configure max file size in mega-bytes, use MB as in 20MB.