You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Mike Blake-Knox <mi...@gmail.com> on 2005/02/02 20:13:57 UTC

RollingFileAppender Exception

If I start my application while there is an old, "unrolled" log file
(e.g., C:\myApp.log last modified 2005-02-01) in the logging
directory, RollingFileAppender reports:

log4net:ERROR [RollingFileAppender] Exception while rolling file
[C:\myApp.log] -> [C:\myApp.log.1]
System.IO.IOException: The process cannot access the file
"C:\myApp.log.1" because it is being used by another process.
 at System.IO.__Error.WinIOError(Int32 errorCode, String str)
 at System.IO.File.Move(String sourceFileName, String destFileName)
 at log4net.Appender.RollingFileAppender.RollFile(String fromFile,
String toFile) in C:\Documents and Settings\mblakeknox\My
Documents\Visual Studio
Projects\CTI\Server\log4net\Appender\RollingFileA
ppender.cs:line 1051
log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but
OutputFile [C:\myApp.log] already exists.

While it's doing this, it successfully renames myApp.log to
myApp.log.2005-02-01, creates a new zero length myApp.log (in
SafeOpenFile(), then when it returns to ExistingInit(), it finds
AppendToFile (why?) is false and reports the internal error.

Here's a FileMon log showing what happened:
2:07:15 PM	CTIServer.e:3952	IRP_MJ_DIRECTORY_CONTROL	C:\	SUCCESS	FileBothDirectoryInformation:
myApp.log*
2:07:15 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	SUCCESS	Attributes:
A
2:07:15 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	SUCCESS	Attributes:
A
2:07:18 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	SUCCESS	Attributes:
A
2:07:18 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log.2005-02-01	FILE
NOT FOUND	Attributes: Error
2:07:18 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	SUCCESS	Attributes:
A
2:07:18 PM	CTIServer.e:3952	IRP_MJ_CREATE
	C:\myApp.log	SUCCESS	Options: Open  Access: All
2:07:18 PM	CTIServer.e:3952	IRP_MJ_QUERY_INFORMATION	C:\myApp.log	SUCCESS	FileAttributeTagInformation
2:07:18 PM	CTIServer.e:3952	FASTIO_QUERY_BASIC_INFO	C:\myApp.log	SUCCESS	Attributes:
A
2:07:18 PM	CTIServer.e:3952	IRP_MJ_CREATE
	C:\myApp.log.2005-02-01	SUCCESS	Options: Open  Access: All
2:07:18 PM	CTIServer.e:3952	IRP_MJ_SET_INFORMATION
	C:\myApp.log	SUCCESS	FileRenameInformation
2:07:18 PM	System:3952	IRP_MJ_CLEANUP	C:\myApp.log.2005-02-01	SUCCESS		
2:07:18 PM	System:3952	IRP_MJ_CLOSE 	C:\myApp.log.2005-02-01	SUCCESS		
2:07:18 PM	CTIServer.e:3952	IRP_MJ_CLEANUP	C:\myApp.log.2005-02-01	SUCCESS		
2:07:18 PM	CTIServer.e:3952	IRP_MJ_CLOSE 	C:\myApp.log.2005-02-01	SUCCESS		
2:07:18 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	FILE NOT
FOUND	Attributes: Error
2:07:18 PM	CTIServer.e:3952	IRP_MJ_CREATE
	C:\myApp.log	SUCCESS	Options: OverwriteIf  Access: All
2:07:18 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	SUCCESS	Attributes:
A
2:07:20 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	SUCCESS	Attributes:
A
2:07:20 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log.1	FILE NOT
FOUND	Attributes: Error
2:07:20 PM	CTIServer.e:3952	FASTIO_QUERY_OPEN	C:\myApp.log	SUCCESS	Attributes:
A
2:07:20 PM	CTIServer.e:3952	IRP_MJ_CREATE 	C:\myApp.log	SHARING
VIOLATION	Options: Open  Access: All

>From this, and knowing that a C:\myApp.log file is left behind but not
a C:\myApp.log.1 fileI think the problem is really that the
RollingFileAppender has kept C:\myApp.log open.

I'm using the following configuration:

 <log4net>
   <appender name="Console" type="log4net.Appender.ConsoleAppender">
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%p %X{MessageID}: %m%n">
       </conversionPattern>
     </layout>
   </appender>
   <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
     <file value="C:\\myApp.log">
     </file>
     <maximumFileSize value="1000KB">
     </maximumFileSize>
     <maxSizeRollBackups value="5">
     </maxSizeRollBackups>
     <rollingStyle value="3"> <!-- Composite -->
     </rollingStyle> 
     <appendToFile value="true">
     </appendToFile>
     <countDirection value="0">
     </countDirection>
        
     <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
     </layout>          
   </appender>
   
   <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
   
<!-- it's not nice but the log4net infrastucture only accepts an IP
address, not a hostname -->
<param name="RemoteAddress" value="176.10.120.167" />
<param name="RemotePort" value="5151" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j">
     </layout>
   </appender>
   <root>
     <level value="ALL">
     </level>
     <appender-ref ref="Console">
     </appender-ref>
     <appender-ref ref="RollingFile">
     </appender-ref> <!-- -->
     <appender-ref ref="UdpAppender">
     </appender-ref>
   </root>
 </log4net>


-- 
Mike Blake-Knox