By default the log4net FileAppender takes an exclusive write lock on the log file. If you have multiple processes that are logging to the same file then you need to use a different locking model. For example the MinimalLock model:
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> This locking model takes a write lock on the file as each logging event written and then releases it immediately. An example configuration is: <appender name="FileAppender" type="log4net.Appender.FileAppender"> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <file value="c:\tmp\test-file.txt" /> <layout type="log4net.Layout.PatternLayout" value="%d [%t] %-5p %c - %m%n" /> </appender> Cheers, Nicko > -----Original Message----- > From: Ramaa Davanagere [mailto:[EMAIL PROTECTED] > Sent: 04 November 2005 17:12 > To: 'Log4NET User' > Subject: RE: What do I need to do to get rid of this error? > Please help > > > > I wish it was that easy!!!! > > > > I have multiple components (20+) using the same log file for > logging messages. I don't think I can check which of the > components is currently locking the files, before writing log > messages. > > > > How do I resolve this? > > > > -----Original Message----- > From: Shireesh Thanneru [mailto:[EMAIL PROTECTED] > Sent: Friday, November 04, 2005 11:55 AM > To: Log4NET User > Subject: Re: What do I need to do to get rid of this error? > Please help > > > > You need to make sure that no other process/program is > accessing the the file at "C:\Program > Files\Mobius\contenuity\LogFiles\vdrconBOLog.txt" > > so that log4net can acquire a lock on that file. > > Ramaa Davanagere <[EMAIL PROTECTED]> wrote: > > > > > > log4net: RollingFileAppender: Searched for existing > files in [C:\Program Files\Mobius\contenuity\LogFiles] > > log4net: RollingFileAppender: curSizeRollBackups starts at [0] > > log4net: FileAppender: Opening file for writing > [C:\Program Files\Mobius\contenuity\LogFiles\vdrconBOLog.txt] > append [True] > > log4net:ERROR [RollingFileAppender] Unable to acquire > lock on file C:\Program > Files\Mobius\contenuity\LogFiles\vdrconBOLog.txt. The process > cannot access the file "C:\Program > Files\Mobius\contenuity\LogFiles\vdrconBOLog.txt" because it > is being used by another process. > > log4net:ERROR [RollingFileAppender] OpenFile(C:\Program > Files\Mobius\contenuity\LogFiles\vdrconBOLog.txt,True) call failed. > > LockStateException: The file is not currently locked > > at log4net.Appender.LockingStream.AssertLocked() > > at log4net.Appender.LockingStream.get_CanWrite() > > at System.IO.StreamWriter..ctor(Stream stream, > Encoding encoding, Int32 bufferSize) > > at System.IO.StreamWriter..ctor(Stream stream, > Encoding encoding) > > at log4net.Appender.FileAppender.OpenFile(String > fileName, Boolean append) > > at > log4net.Appender.RollingFileAppender.OpenFile(String > fileName, Boolean append) > > at log4net.Appender.FileAppender.SafeOpenFile(String > fileName, Boolean append) > > log4net: FileAppender: Opening file for writing > [C:\Program Files\Mobius\contenuity\LogFiles\vdrconBOLog.txt] > append [True] > >