Avatar of odumbe
odumbe

asked on 

Log4j

I have written a simple Java class and inlcuded log4j.jar in the classpath.

In log4j.properties I have written
log4j.rootCategory=DEBUG, C:\\logger.txt
log4j.appender.dest1=org.apache.log4j.ConsoleAppender
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

and in my class I have written

import org.apache.log4j.*;

public class myclass {
      static Logger logger = Logger.getLogger(myclass .class);

public static void main(String[] args) {
logger.debug("111111111111111111111111111");
}

But I am getting the following error

log4j:ERROR Could not find value for key log4j.appender.C:\logger.txt
log4j:ERROR Could not instantiate appender named "C:\logger.txt".
log4j:WARN No appenders could be found for logger (com.myclass).
log4j:WARN Please initialize the log4j system properly.

Also nothing gets written to logger.txt
How can I fix this.
Java

Avatar of undefined
Last Comment
elfe69
Avatar of odumbe
odumbe

ASKER

Also tried chaging
static Logger logger = Logger.getLogger(myclass .class);

to
static Logger logger = Logger.getLogger(com.myclass .class);

where com is the package name but still same problem.
ASKER CERTIFIED SOLUTION
Avatar of elfe69
elfe69
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo