If you remove the appender programmatically you have to call Close() on it.
Nicko > -----Original Message----- > From: Shaily Goel [mailto:[EMAIL PROTECTED] > Sent: 25 August 2005 15:31 > To: [email protected]; Nicko Cadell > Subject: Error in RollingFileAppender > > hi > > I am using RollingFileAppender provided by log4net(I am using > incubating-log4net-1.2.9-beta) > > 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 process." > > 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> > [STAThread] > 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; > log.AddAppender(CreateRollingFileAppender()); > ILog logger = LogManager.GetLogger("TestLogger"); > > logger.Error("This is test message: "); > > log.RemoveAppender("CustomRoller"); > log.AddAppender(CreateRollingFileAppender()); > 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 = > RollingFileAppender.RollingMode.Size; > appender.MaxSizeRollBackups = 10; > appender.MaximumFileSize = "1KB"; > appender.Layout = layOut; > appender.ActivateOptions(); > return appender; > } > > > } > } > > >>> [EMAIL PROTECTED] 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 > http://logging.apache.org/log4net/downloads.html > > > > 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 rest of the code. > Unlike DateTime.ToString equivalent java date pattern > renderer supports the day of week. > > Cheers, > Nicko > >
