Friday, September 29, 2006

Programatically adding appender to Log4j

Wanted to use Log4j without configuration file.
So here is the clean code.

//Java

FileAppender fa = new FileAppender(new SimpleLayout(),filename,true);


fa.activateOptions();
Logger logger = Logger.getLogger(filename);
logger.addAppender(fa);
logger.info(data);
logger.removeAllAppenders();

2 comments:

Anonymous said...

Just keep posting good stuff.

Anonymous said...

Hi,
I am quite impressed with this site and the contributions. I am happy that I am part of this site and I wish to contribute regularly.
Thanks