0

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

Philipp M
  • 1,877
  • 7
  • 27
  • 38
Patrick
  • 5,442
  • 9
  • 53
  • 104

2 Answers2

2

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

Cole W
  • 15,123
  • 6
  • 51
  • 85
0

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

Community
  • 1
  • 1
julien
  • 3
  • 4