Hi, I am using Java 1.6 and log4j 1.2.15 with Easy Eclipse Server 1.2.2.2 to develop a simple test program.
I wanted to log a few things about this program and then I decided to use log4j to that, but it seems I am not being able to configure it correctly. Whenever I run my application I get this error:
The part of my app that is initializing log4j is:
And my log4j.xml is below:
Finally I found somewhere in the net the following test to see if my application could find the log4j.xml file or not:
I have run my application with this code and I keep getting the Not OK message.
Also I have tried to use the full path to the log4j.xml (c:\workspace\...\log4j.xml) as the argument for the PropertyConfigurator.Configure() method and the test above. I found out that this way my program actually finds the log4j.xml, but no log file is generated, nor any text is ouputted to the console even though the FileNotFoundException is not thrown.
Please help me.
Thanks a lot,
Komyg
I wanted to log a few things about this program and then I decided to use log4j to that, but it seems I am not being able to configure it correctly. Whenever I run my application I get this error:
Code:
log4j:ERROR Could not read configuration file [log4j.xml].
java.io.FileNotFoundException: log4j.xml (The system cannot find the specified file)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:316)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:342)
at com.itautec.comparadorNeurotech.Program.main(Program.java:90)
log4j:ERROR Ignoring configuration file [log4j.xml].
The part of my app that is initializing log4j is:
Code:
java.io.File f = new java.io.File("log4j.xml");
if (f.exists())
System.out.println("OK!");
else
System.out.println("Not OK!");
PropertyConfigurator.configure("log4j.xml");
Logger log = Logger.getLogger(Program.class);
log.info("Iniciando o Comparador Neurotech.");
And my log4j.xml is below:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="[URL unfurl="true"]http://jakarta.apache.org/log4j/">[/URL]
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd hh:mm:ss} [%-5level] %type.%method - %message%newline" />
</layout>
</appender>
<appender name="LogFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="c:\Temp\ComparadorNeurotech.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd hh:mm:ss} [%-5level] %type.%method - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
</log4j:configuration>
Finally I found somewhere in the net the following test to see if my application could find the log4j.xml file or not:
Code:
java.io.File f = new java.io.File("log4j.xml");
if (f.exists())
System.out.println("OK!");
else
System.out.println("Not OK!");
I have run my application with this code and I keep getting the Not OK message.
Also I have tried to use the full path to the log4j.xml (c:\workspace\...\log4j.xml) as the argument for the PropertyConfigurator.Configure() method and the test above. I found out that this way my program actually finds the log4j.xml, but no log file is generated, nor any text is ouputted to the console even though the FileNotFoundException is not thrown.
Please help me.
Thanks a lot,
Komyg