Patrick
Patrick

Reputation: 5592

RollingFileAppender to follow date and produce textfiles?

I got this:

<appender name="iOsClients_Error" type="log4net.Appender.RollingFileAppender">
    <file value="Logs/errors/error_"/>
    <appendToFile value="true"/>
    <rollingStyle value="Date"/>                
    <datePattern value="yyyyMMdd" />
    <staticLogFileName value="false"/>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%newline%date [%thread] %-5level - %message%newline%newline%exception%newline%newline"/>
    </layout>
</appender>

This will create a log file like: error_20110801

How can I get log4net to output text files or how can I get log4net to add the .txt file extension to these files?

I want this: error_20110801.txt

Upvotes: 0

Views: 212

Answers (2)

julien
julien

Reputation: 3

The problem with

<file type="log4net.Util.PatternString" value="Logs/errors/error_%date{yyyyMMdd}.txt" />

is that if the server doesn't restart every day, the file will have the same date, so the same name. And the archived file will be like error_20130101.txt20130101 . The solution to this is here actually : Setting a log file name to include current date in Log4j

Upvotes: 0

Cole W
Cole W

Reputation: 15303

You can use something like this to accomplish that:

<file type="log4net.Util.PatternString" value="Logs/errors/error_%date{yyyyMMdd}.txt" />

They key here is to use the PatternString

Upvotes: 2

Related Questions