Hi All,
I am new to Log4j, so forgive me in case I am asking too trivial quesion.
The follwing code works fine, when I create a new project in Eclipse
and run that code, it creates log file under c:\Temp, but when same
file I copy to a existing project having multiple packages, it does
not work and log file gets created under c:\Temp but nothing is
written in that.
Can some body tell me where I am wrong please ?
Regards
Ravi.
import java.io.File;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.apache.log4j.Category;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.RollingFileAppender;
import org.apache.log4j.Category;
import org.apache.log4j.Level;
/**
* Logging Sample.
* @author Ravi
*
*/
public class TestLogging
{
public static final Logger aLogger = Logger.getLogger(TestLogging.class);
String aLogFile;
public void doLogging ()
{
aLogger.info("test log");
}
public static void main (String[] args)
{
TestLogging testLogging = new TestLogging();
testLogging.startLogging();
testLogging.doLogging();
}
public void startLogging ()
{
PatternLayout layout = new PatternLayout("%d [%p] %c %m%n");
String logFolder = "C:\\Temp";
aLogFile = logFolder + "\\" + "TestLogging" + ".log";
ConsoleAppender con = new ConsoleAppender(layout);
con.setName("ConsoleLog");
con.setThreshold(Level.INFO);
aLogger.addAppender(con);
try
{
File aFile = new File(logFolder);
aFile.mkdirs();
RollingFileAppender file = new RollingFileAppender(layout,
aLogFile);
file.setName("FileLog");
file.setMaxFileSize("1MB");
file.setThreshold(Level.INFO);
aLogger.addAppender(file);
}
catch (IOException ex)
{
aLogger.warn("Failed to create file appender", ex);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]