Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem in addAppender() method in Log4j API

Tags:

java

log4j

Hi I'm using log4j api for logging purpose. When I use the following code to append to the appender, it's showing "addAppender() is undefined for the type Logger" error

FileAppender myAppender = new FileAppender(new PatternLayout(),"output.log");
Logger.getLogger(ConfigFileReader.class.getName()).addAppender(myAppender);

Can anyone tell me what should I do to debug this error?

like image 323
raja Avatar asked Sep 19 '26 06:09

raja


1 Answers

Are you sure that you are importing the correct Logger class? A common error is to import java.util.Logger instead of the Logger from the log4j package.

like image 183
Martin OConnor Avatar answered Sep 20 '26 20:09

Martin OConnor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!