pmn
pmn

Reputation: 2247

How to onfigure Log4Net to rolling everyday?

I want to configure Log4Net to rolling every day, I mean i want it take log everyday in new file, so i config Log4Net like this in my App.config:

<?xml version="1.0" encoding="utf-8"?>
 <configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
 <log4net>
   <root>
     <level value="DEBUG" />
     <appender-ref ref="FileAppender" />
   </root>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString" value="E:/MyLog_" />
  <staticLogFileName value="False" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <datePattern value="yyyy.mm.dd'.log'" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date{dd/MM/yyyy HH:mm:ss.fff} - %level - %message%newline" />
  </layout>
 </appender>   
</log4net>
 <startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 </startup>
</configuration>

but it does not work, what is the problem?

Upvotes: 0

Views: 161

Answers (2)

Grant Winney
Grant Winney

Reputation: 66439

Your date format appears to be incorrect. If they use the same Date and Time Formatters as Microsoft (I don't know if they do for sure, but they're fairly universal), then mm represents minutes, not days.

Per the log4net documentation, try changing the lowercase mm to an uppercase MM.

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

Upvotes: 1

Sivakumar
Sivakumar

Reputation: 1751

Try this:

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

Upvotes: 1

Related Questions