The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
M.Suarez
 |
| 06/15/2009 11:21 PM |
|
Hi,
I am trying to just have the latest 2 log files of my application, thus I have configured the log4net as follows:
<log4net> <appender name="RollingFile" type="log4net.Appender.RollingFileAppender"> <file value="d:\netapps\logfiles\MyApp.log" /> <appendToFile value="true" /> <MaximumFileSize value="100KB"/> <MaxSizeRollBackups value="2" /> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" /> </layout> </appender>
<!-- Set root logger level to INFO and its only appender to Console and RollingFile--> <root> <level value="INFO" /> <appender-ref ref="RollingFile" /> </root> </log4net>
However, there will be more than then two expected log files, this is because: "The maximum applies to each time based group of files and not the total" (http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAppender.MaxSizeRollBackups.html)
How should I configure log4net then to only store the latest two files? Any help will be greatly appreciate it.
Regards, Monica |
|
|
|
|
Ron Grabowski
 |
|
Radovan Raszka
 |
| 06/17/2009 7:37 AM |
|
Deleting old log files is thing I'm interested in too. According to doc I think MaxSizeRollBackups has reason only when logs are rolled over size (you have more log files per day). But it probably doesn't work when log is rolled over date only (one log per day only). Is it true or not? My appender is configured as follows: <appender name="RollingFile" type="log4net.Appender.RollingFileAppender"> <appendToFile value="true" /> <file value="Log/Service.log" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{HH:mm:ss,fff} %5level [%2thread] %message (%logger{1}:%line)%n" /> </layout> <rollingStyle value="Date" /> <Threshold value="DEBUG" /> </appender> But I don't know how to set it to keep last 10 logs. Now I delete old logs in my app - I run clean procedure once a day and delete logs whose last modification was done before 10 days... Radovan
|
|
|
|
|
M.Suarez
 |
| 06/18/2009 10:44 PM |
|
Thanks for tip. I will add that and see what happens. Will let you know.
One thing, you have put there the link to the log4net config examples, however none of them seem to be using the property you just mention.
Also I found this: https://issues.apache.org/jira/browse/LOG4NET-208
|
|
|
|
|
M.Suarez
 |
| 06/18/2009 10:53 PM |
|
I have just checked and this is what happened: log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [RollingMode] to se t object on [log4net.Appender.RollingFileAppender]
|
|
|
|
|
M.Suarez
 |
| 06/18/2009 10:55 PM |
|
I too clear the old log files from my app, but i believe that there must be a way to configure this, thus the log4net takes care of it, right? or doesn't?
|
|
|
|
|
Ron Grabowski
 |
| 06/19/2009 6:05 AM |
|
Hopefully you glanced at the public properties on RollingFileAppender and realized that the property is actually called RollingStyle:
<RollingStyle value="Size" />
|
|
|
|
|
Ron Grabowski
 |
| 06/19/2009 6:15 AM |
|
While this might not be the exact answer you were looking for, don't forget that sometimes its easier to just write the 3 lines of code yourself for deleting old log files and move on to other things:
foreach (string file in Directory.GetFiles("c:\\logs", "*.log")) { if (DateTime.Today.Subtract(File.GetLastWriteTime(file)).Days > 10) { File.Delete(file); } }
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|