Try the following:

  public static Category CAT = org.apache.log4j.Category.getInstance(Log4jEmailTest.class.getName());

  public static void main(String[] args)
  {
    String fileName = "c:/tmp/log4j.config";
    File checkFile = new File(fileName);
    if (fileName != null && new File(fileName).exists())
    {
      PropertyConfigurator.configure(fileName);
      CAT.error("File "+checkFile.getName()+" found!");
    }
    else
    {
        CAT.debug(" file or fileName is missing");
    }

    for (int i=0;i<15;i++)
    {
      CAT.error("Test error, error, test, test, fatal error i = "+i);
    }
  }

As you can see you need to specify a certain file.

 

Here is an example for the content of you config file

#------------------------------------------root category-----------------------

# Set root category priority to DEBUG and its appenders to sysout.

log4j.rootCategory=DEBUG, sysout, SMTPTest

# sysout is set to be a FileAppender which outputs to System.out

log4j.appender.sysout=org.apache.log4j.ConsoleAppender

# the following line only if all the logging should to System.out as well

#log4j.appender.sysout.File=System.out

 

 

# sysout also uses PatternLayout.

log4j.appender.sysout.layout=org.apache.log4j.PatternLayout

log4j.appender.sysout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

 

-----Original Message-----
From: Sonia Jose [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 22, 2001 10:58 AM
To: [EMAIL PROTECTED]
Subject: configuration problem.

Hi.. I am new to Log4j and I as I was going through the mannual I saw MyApp. java. With BasicConfigurator.configure() the program works fine. But when I use PropertyConfigrator, where to keep the properties file. How should I name the
properties file? Is it *.properties? When I run the java program, how to associate this properties file to the program.
 
Thanks
Sonia

Reply via email to