Ok I found out how to do that.
Its just a component builder added to the AppenderBuilder:
ComponentBuilder rollOverStrategy =
builder.newComponent("DefaultRolloverStrategy").addAttribute("max", 5);
...
mainLogBuilder .addComponent(rollOverStrategy)
On 2020/02/22 16:59:16, [email protected] <[email protected]>
wrote:
> Hello everyone,
> coming from the old log4j I'm trying to migrate our XML configuration into
> just code.
> Sadly I cannot find any info about how to set a rolloverStrategy
> programmatically.
> I am using this code to initialize a mainLogBuilder.
>
> LayoutComponentBuilder layoutBuilder =
> builder.newLayout("PatternLayout").addAttribute("pattern", LOG_PATTERN);
> ComponentBuilder triggeringRollFile =
> builder.newComponent("Policies").addComponent(builder.newComponent("SizeBasedTriggeringPolicy").addAttribute("size",
> LOG_SIZE));
>
> builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT,
> Filter.Result.NEUTRAL).addAttribute("level", Level.INFO));
> AppenderComponentBuilder mainLogBuilder = builder
> .newAppender("mainLog", "RollingFile")
> .addAttribute("fileName", "log/main.log")
> .addAttribute("filePattern", "log/main.%i.log")
> .add(layoutBuilder)
> .addComponent(triggeringRollFile);
>
> But I want to set the max number of backup files to 5. How do I do this?
>
> Thanks in advance
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]