log4j2属性替换-带有外部属性文件

t98cgbkg  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(349)

在我的应用程序中,我有一个外部属性文件,我试图使用这个文件在log4j2.xml中定义一些属性
有人知道怎么做吗?
提前谢谢。
[已编辑]
我想我的问题还不清楚,我有一个springboot模块,它使用一个外部属性文件而不是application.properties。问题是当我这么做的时候${bundle:application:file.name}它可以工作,但是现在application.properties被更改到另一个位置(比如d:/myproperties.properties),我的log4j2.xml无法识别属性“myfilename”。

vjhs03f7

vjhs03f71#

您可以使用属性替换,log4j 2支持在配置中指定令牌作为对其他地方定义的属性的引用。https://logging.apache.org/log4j/2.0/manual/configuration.html#propertysubstitution

<Configuration status="debug">
    <Appenders>
        <Appender type="File" name="File"
                  fileName="${sys:testAppLogPath:-default/location/of/testApp.log}">

    </Appenders>
</Configuration>

相关问题