Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a sample code to work with the log4j library, but I encountered an error as mentioned below. Additionally, a new log4j file isn't being created. Can anyone help me understand why this error is occurring?

What I have tried:

This is my class file

package log4j_testing;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class log4jexample {
	
static Logger logger=Logger.getLogger(log4jexample.class);
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		PropertyConfigurator.configure("log4j.properties");
		logger.debug("this is a debug");
		logger.info("this is an info");
		logger.warn("this is a warning");

	}

}



and this is my log4j.propertiesfile

log4j.rootLogger=INFO , file

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\1.SUBJECTS\SEMESTER 07\SELF_QA\LOg4jExamplefiles\logging.log
log4j.appender.file.MaxFileSize=12MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Posted
Comments
Richard MacCutchan 15-Jan-24 4:26am    
What is the error you encountered and where did it occur?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900