如何获取log4j日志文件的位置? Log4j ver 2.3配置:
<Appenders>
<RollingFile name="ROLLLOGAPPENDER" fileName="./log/${infoFile}.log" filePattern="./log/${infoFile}-%i.log" append="true">
<PatternLayout pattern="%d %-5p [%c{1}] %m%n"/>
<ThresholdFilter level="${stdLevel}" onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<SizeBasedTriggeringPolicy size="${sizeOfFile}" />
</Policies>
<DefaultRolloverStrategy max="${filesCount}"/>
</RollingFile>
<Async name="ASYNC-LOG">
<AppenderRef ref="ROLLLOGAPPENDER"/>
</Async>
</Appenders>
但它不起作用:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.RollingFileAppender;
import org.apache.logging.log4j.core.config.Configuration;
...
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
RollingFileAppender techical = (RollingFileAppender) config.getAppender(FILE_APPENDER_NAME);
java.lang.ClassCastException:
org.apache.logging.log4j.core.appender.AsyncAppender cannot be cast to org.apache.logging.log4j.core.appender.RollingFileAppender