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 "Stewart, Mark (GE Consumer Finance, consultant)" <ms...@wmcdirect.com> on 2005/06/03 15:26:08 UTC
File Access Error with RollingFileAppender
> I am having problems with the log4net in a small test project (Using VS.NET 2003, and log4net (1.2.0 Beta 8)). It works fine when I use the ConsoleAppender, but fails to log some messages with the RollingFileAppender.
>
> I have a simple log4net test solution with a primary project and a library project with a simple class and log method.
> Both projects call log4net.Config.DOMConfigurator.Configure() on startup, and set the class-level variables:
>
> private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(TestClass));
> private static readonly bool isDebugEnabled = log.IsDebugEnabled;
> private static readonly bool isInfoEnabled = log.IsInfoEnabled;
>
> The primary project logs fine, but the library class instance fails to log to the file when instantiated and called,
> and I get the following trace output:
>
> log4net: FileAppender: Opening file for writing [C:\Myfiles\MyProjects\Log4NetTest\LogTest.log] append [True]
> log4net:ERROR RollingFileAppenderOpenFile(,True) call failed.
> System.IO.IOException: The process cannot access the file "C:\Myfiles\MyProjects\Log4NetTest\LogTest.log" because it is being used by another process.
>
> When I debug through the code, I find that the writer for the failing class instance is "not defined".
>
> Here is my config file...
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <!-- Register the section handler for the log4net section -->
> <configSections>
> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
> </configSections>
>
>
> <log4net debug="true">
>
> <appender name="RollingLogger" type="log4net.Appender.RollingFileAppender,log4net">
> <param name="File" value="C:\\Myfiles\\MyProjects\\Log4NetTest\\LogTest.log" />
> <param name="AppendToFile" value="true" />
>
> <param name="MaxSizeRollBackups" value="10" />
> <param name="MaximumFileSize" value="100KB" />
> <param name="RollingStyle" value="Composite" />
> <param name="DatePattern" value="yyyyMMdd" />
> <param name="StaticLogFileName" value="true" />
>
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
>
> <layout type="log4net.Layout.PatternLayout,log4net">
> <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
> </layout>
> </appender>
>
> <appender name="DefaultLogger" type="log4net.Appender.ConsoleAppender" >
> <layout type="log4net.Layout.PatternLayout">
> <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
> </layout>
> </appender>
>
> <root>
> <level value="DEBUG" />
> <appender-ref ref="RollingLogger" />
> </root>
>
>
>
> </log4net>
>
>
> </configuration>
>
I tried adding, then removing the <lockingModel> subkey for the appender, with no change.
As I said, the logging works fine with the ConsoleAppender, but not the file.
> Is this a known problem, or I am I doing something wrong?
>
>
> Thanks,
>
> Mark Stewart
> MStewart@wmcdirect.com
>
>