logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shaily Goel" <gsha...@novell.com>
Subject Error in RollingFileAppender
Date Thu, 25 Aug 2005 14:30:51 GMT
I am using RollingFileAppender provided by log4net(I am using
My scenario is : Configuration of Appender changes periodically(e.g
RollingMode, No of backup copies, FileSize but the FileName remain's
same) . So I remove the previous appender and add new appender again
with new configuration.
But I found that When I remove Appender it still holds the stream to
the file and so a new appender is not able to write to same file. Please
let me know the solution of this.
Error is : "log4net:ERROR [RollingFileAppender] Unable to acquire lock
on file C:\TestFolder\Roll\roller.txt. The process cannot access the
file "C:\TestFolder\Roll\roller.txt" because it is being used by another
Below is the code snippet for testing the above scenario
using System;
using System.IO;
using log4net;
using log4net.Appender;

using log4net.Layout;
using log4net_Logger = log4net.Repository.Hierarchy.Logger;
using log4net.Repository.Hierarchy;
using log4net.Core;
namespace TestRoller
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 class TestClass
  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  static void Main(string[] args)
            log4net_Logger log =
LogManager.GetLogger("TestLogger").Logger as log4net_Logger;
            log.Level = Level.Info;
            log.Additivity = false;
            log.Repository.Configured = true; 
            ILog logger = LogManager.GetLogger("TestLogger");
            logger.Error("This is test message: ");
            logger.Error("This is new test message: " );
        private static RollingFileAppender CreateRollingFileAppender()
            RollingFileAppender appender = new RollingFileAppender();
            SimpleLayout layOut = new SimpleLayout();
            appender.Name = "CustomRoller";
            appender.File = "C:\\TestFolder\\Roll\\roller.txt";
            appender.AppendToFile = true;           
            appender.RollingStyle =
            appender.MaxSizeRollBackups = 10;
            appender.MaximumFileSize = "1KB";
            appender.Layout = layOut;
            return appender;

>>> nicko@neoworks.com 08/18/05 5:34 PM >>>

> Thanks for a quick reply.  I am facing the following problems 
> regarding the use of DatePattern in RollingFileAppender:
> 1. I used DatePattern as "yyyy-MM" to Roll at the beginning 
> of each month like below:

This pattern is correct and it works with log4net 1.2.9

> 2. I am unable to identify the DatePattern that I should use 
> to roll the log each week(RollPoint.TopOfWeek). Please let me 
> know by example the DatePattern I should use for rolling the 
> log each week. If "RollPoint.TopOfWeek" option is used then 
> at which day of the week the rolling will take place . Is it 
> the first day of the week, which can be different depending 
> on the locale or the last day of the week or some defined day only??

As DateTime.ToString does not have a pattern that supports the day of
the week it is not possible to use RollPoint.TopOfWeek. This value
exists only because it exists in log4j and was ported over with the
of the code. Unlike DateTime.ToString equivalent java date pattern
renderer supports the day of week.


View raw message