Java Log4j2 HTMLLayout配置和输出

Java Log4j2 HTMLLayout配置和输出,java,swing,logging,log4j,log4j2,Java,Swing,Logging,Log4j,Log4j2,我试图在我的Swing应用程序中包含Log4J,当我每次尝试搜索Log4J 1.x教程而不是Log4J2时,事情变得很混乱,我相信可能没有太大的变化,但在这两者之间,我没有得到一个HTML日志文件作为输出,正如我在下面的设置中预期的那样 本人遵照以下指示: 属性文件: 初始化: 写入日志: 我的印象是,即使只记录了一行日志,我也应该生成一个日志文件,但事实并非如此。 我做错了什么 我尝试在Apache的2.10版本中搜索.properties文件更改,但没有消除任何疑问 如果需要知道的话,我正在

我试图在我的Swing应用程序中包含Log4J,当我每次尝试搜索Log4J 1.x教程而不是Log4J2时,事情变得很混乱,我相信可能没有太大的变化,但在这两者之间,我没有得到一个HTML日志文件作为输出,正如我在下面的设置中预期的那样

本人遵照以下指示:

属性文件:

初始化:

写入日志:

我的印象是,即使只记录了一行日志,我也应该生成一个日志文件,但事实并非如此。 我做错了什么

我尝试在Apache的2.10版本中搜索.properties文件更改,但没有消除任何疑问

如果需要知道的话,我正在使用NetBeans 8.2

阿西夫
看起来您在示例中使用的是旧的1.2.7 log4j.properites文件

使用此链接

它包括一个log4j2.properies文件,以及从博客下面复制的文件

status = error
name = PropertiesConfig

#Make sure to change log file path as per your need
property.filename = C:\\logs\\app-info.html

filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = debug

appenders = rolling

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.html.gz
appender.rolling.layout.type = HTMLLayout
appender.rolling.layout.charset = UTF-8
appender.rolling.layout.title = Howtodoinjava Info Logs
appender.rolling.layout.locationInfo = true
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20

loggers = rolling

#Make sure to change the package structure as per your application
logger.rolling.name = com.howtodoinjava
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile

向我们展示如何初始化LOGGER@HaimRaman感谢您指出,更新了我的问题:关于log4j.rootLogger=DEBUG,HTMLMy-bad,它已经在程序中了,忘了从顶部复制。可以添加pom.xml吗谢谢!成功了,唯一剩下的就是我用来为每次运行生成新日志文件的技巧${current.date.time},如果你找到了什么,请告诉我。否则我可以接受我们所得到的:
// Static block to create new System Property that help us creating new Log time every run
    static{

        SimpleDateFormat dateFormat = new SimpleDateFormat("MMddyyyyhhmmss");
        System.setProperty("current.date.time", dateFormat.format(new Date()));
    }
// Initiate Logger instance
private static final Logger LOGGER = LogManager.getLogger(MainWindow.class);
public static void main(String args[]) {

        // Log
        LOGGER.debug("Application Initializing");
//...Other code follows for JFrame and components initialization 
status = error
name = PropertiesConfig

#Make sure to change log file path as per your need
property.filename = C:\\logs\\app-info.html

filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = debug

appenders = rolling

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.html.gz
appender.rolling.layout.type = HTMLLayout
appender.rolling.layout.charset = UTF-8
appender.rolling.layout.title = Howtodoinjava Info Logs
appender.rolling.layout.locationInfo = true
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20

loggers = rolling

#Make sure to change the package structure as per your application
logger.rolling.name = com.howtodoinjava
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile