如何在Log4J2 Properties文件中配置minSize=0
Got it, let's walk through this! When switching from Log4J2's XML/JSON-style config to Properties files, you just need to adapt to the flat, dot-separated structure that Properties uses. Here's exactly how to set minSize to 0 for OnStartupTriggeringPolicy:
In Log4J2 Properties config, you define components by their type and nest them under parent components using dots. For an OnStartupTriggeringPolicy attached to a RollingFileAppender, your config will follow this pattern:
# Replace <your-appender-name> with your actual appender's name (e.g., "rollingFile") appender.<your-appender-name>.policy.type = OnStartupTriggeringPolicy appender.<your-appender-name>.policy.minSize = 0
Example with a concrete appender name
If your appender is named myAppLog, the working config would look like this:
appender.myAppLog.policy.type = OnStartupTriggeringPolicy appender.myAppLog.policy.minSize = 0
This tells Log4J2 to create an OnStartupTriggeringPolicy instance for your appender, with the minimum file size threshold set to 0 bytes. That means the policy will trigger a log rollover on application startup no matter how small the current log file is.
内容的提问来源于stack exchange,提问作者Configueroa

