Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.0.8
-
None
-
None
-
Patch
Description
with log4net's RollingFileAppender [config example|http://logging.apache.org/log4net/release/config-examples.html] ,when I add datepattern set , RollingFileAppender will work with
INTERNAL ERROR。
InternalDebugging output:
log4net: Moving [C:\Users\tiger\Source\Repos\MyAes\ConsoleApp1\bin\Debug\test.log] -> [C:\Users\tiger\Source\Repos\MyAes\ConsoleApp1\bin\Debug\test.log2019-12-07 14:10:37]
log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [C:\Users\tiger\Source\Repos\MyAes\ConsoleApp1\bin\Debug\test.log] already exists.
log4net: Opening file for writing [C:\Users\tiger\Source\Repos\MyAes\ConsoleApp1\bin\Debug\test.log] append [False]
The reason is that the datePatter ,which as part of filename , has some invalid char。In my case, the ":" is invalid filename char on Windows。 So function RollFile 's Moving operation could not success,which leads functionOpenFile get INTERNAL ERROR。
without InternalDebugging in produnction , the INTERNAL ERROR is confusing and without clear reason。 Maybe we should check the filename pattern as soon as possible,I wrote a little patch to check the datePattern in function ActivateOptions,wish it would help。The patch will check filename and reset datePattern if needed,with output as follows:
log4net:WARN datepattern has invalid filename chars, it will replaced by [yyyy-MM-dd HH_mm_ss]
example config with datePattern set:
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="test.log"/>
<appendToFile value="true"/>
<maximumFileSize value="100KB"/>
<maxSizeRollBackups value="2"/>
<datePattern value="yyyy-MM-dd HH:mm:ss"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %thread %logger - %message%newline"/>
</layout>
</appender>