来自:http : //www.gunith.com/2010/11/how-to-get-the-file-path-of-a-
log4j-log-file/
假设log4j.properties文件如下所示,
log4j.logger.migrationlog = INFO, migrationlog4j.appender.migration = org.apache.log4j.RollingFileAppenderlog4j.appender.migration.File = C:/work/log/migration.loglog4j.appender.migration.MaxFileSize=20MBlog4j.appender.migration.MaxBackupIndex=1log4j.appender.migration.layout = org.apache.log4j.PatternLayoutlog4j.appender.migration.layout.conversionPattern = %d %-5p %c - %m%n
在这种情况下,您的Java代码应如下所示,
Logger logger = Logger.getLogger("migrationlog"); //Defining the LoggerFileAppender appender = (FileAppender)logger.getAppender("migration");return new File(appender.getFile());注意, 迁移日志 用于在第一行中创建记录器对象。而 迁移 来获得,后者又调用的GetFile()来获取日志文件对象FileAppender。



