Mike, 

I have checked in a change to the RollingFileAppender that corrects a
potential double open if the initial file is from a different date
period. Is it possible for you to rebuild from CVS and verify that this
update fixes the issue you are seeing?

> [snip]
> 
> 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.

For the RollingFileAppender AppendToFile only applies to the first file
the appender finds on Init. Once the appender starts rolling it forces
AppendToFile to be false. This should be ok because when the appender
opens the new file for writing it should have rolled the old file away,
there should never be case where, after rolling, the file needs to be
opened for append. Hence the internal error message - which is exactly
what it is.


> [snip]
> 
> 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.

You're right about the bogus error text from File.Move. If the native
move call fails the File.Move just raises an exception saying that the
error occurred on the destination file. It knows what the error was from
the Win32 last error code, but not which file, source or destination, so
it just assumes that it is more likely the destination that is causing
the error!


> 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>

You can write these as a single tag without the separate close, i.e.
<file value="C:\\myApp.log" />

Unless you need to set specific properties on the child object itself
(e.g. the conversionPattern on a layout of type PatternLayout) then you
can just use the value attribute and close the element inline.


>      <maximumFileSize value="1000KB">
>      </maximumFileSize>
>      <maxSizeRollBackups value="5">
>      </maxSizeRollBackups>
>      <rollingStyle value="3"> <!-- Composite -->
>      </rollingStyle> 

The rollingStyle value is an Enum. The textual value is converted to the
enum value using Enum.Parse which will accept the string names for the
enum values, i.e. you can write:
<rollingStyle value="Composite" />


>      <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" />

I have committed to CVS an update that allows you to specify either an
IPAddress quad or a DNS hostname. Obviously if you need to specify a
broadcast address you will need to do so via the IPAddress quad,
otherwise you can use the DNS hostname. If the hostname resolves to
multiple IP addresses then the first address returned will be used.


> <param name="RemotePort" value="5151" />

You can write this as:
<remotePort value="5151" />

In general the config parser treats <param name="XXX" value="YYY" /> as
equivalent to <XXX value="YYY" />. The XXX bit is matched case
insensitively to a property on the object.

Cheers,
Nicko


> <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
> 

Reply via email to