views:

2915

answers:

3

Hi,

I want my logfile to look something like this: 2009-02-13.log

but the problem is that I can't seem to find any way to add the .log extension.

I've tried a lot of things but nothing helps. This is what I have this far:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
     <file value="Logs/Log4Net/.log"/>
    <appendToFile value="true"/>
    <rollingStyle value="Date"/>
     <datePattern value="yyyy-MM-dd" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
    </layout>
  </appender>

Kind regards,

Sem

+16  A: 

Sem,

Try adding the .log extension to your date pattern like so and remove it from the file attribute.

<datePattern value="yyyy-MM-dd.lo\g"/>

-Woody

gwhitake
thx, this dit the trick for me.
Sem Dendoncker
+1 Had a similar problem, worked like a charm! Thanks!
Rob
+4  A: 

add ".lo\g" to the end of your datepattern

thx, this dit the trick for me
Sem Dendoncker
+22  A: 

The other answers escape the "g" in "log" since "g" is a special character in datePattern. This isn't wrong, but I prefer to wrap the entire set of non-date characters in single quotes, like so:

<datePattern value="yyyy-MM-dd'.log'" />

This gives the same results, but is easier for me to manage. This way, I don't have to recall which specific characters are special for datePattern (the list is long and varied). If I forget one character then I don't run the risk of borking my file names; they're all nicely escaped en masse.

Craig Walker