我正在尝试通过java代码创建一个RollingFileAppender。下面的代码总是抛出一个空指针异常的行appender.start()声明RollingFileAppender 'null': No name provided
。我无法设置名称,因为名称通常是由RollingFileAppender插件设置。
https://logging.apache.org/log4j/2.x/log4j-core/apidocs/src-html/org/apache/logging/log4j/core/appender/RollingFileAppender.html请建议如何示例化RollingFileAppender。
public static RollingFileAppender getAppender() {
final TimeBasedTriggeringPolicy timeBasedPolicy = new TimeBasedTriggeringPolicy.Builder().withModulate(true).build();
timeBasedPolicy.start();
RollingFileAppender appender = new RollingFileAppender.Builder()
.withFileName("fileName")
.withFilePattern("pattern")
.withPolicy(timeBasedPolicy)
.build();
appender.start();
return appender;
}
1条答案
按热度按时间5t7ly7z51#
聚甲醛
错误