You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Davyd McColl (Jira)" <ji...@apache.org> on 2022/01/24 07:20:00 UTC
[jira] [Commented] (LOG4NET-672) Previous rolled files not taken into consideration after restart the Logging Manager with a specific date-pattern
[ https://issues.apache.org/jira/browse/LOG4NET-672?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17480857#comment-17480857 ]
Davyd McColl commented on LOG4NET-672:
--------------------------------------
I've started to look into this - I first wanted to have an included application to repro the issue, and now I've stumbled across something I'm trying to fix along the way: at some point (either dotnet 5 or dotnet 6 - I haven't tested 5 yet, but 6 has the issue and framework 462 doesn't), the xml appender has been broken by Microsoft deciding that XmlWriter's WriteStartElement should simply throw an error when the element is namespaced (eg `log4net:event`) and I haven't figured out the correct magic yet to work around this behavior. I am, however, looking into both as a unit.
> Previous rolled files not taken into consideration after restart the Logging Manager with a specific date-pattern
> ------------------------------------------------------------------------------------------------------------------
>
> Key: LOG4NET-672
> URL: https://issues.apache.org/jira/browse/LOG4NET-672
> Project: Log4net
> Issue Type: Bug
> Components: Appenders
> Affects Versions: 2.0.10
> Reporter: Akhil Bandari
> Priority: Critical
>
> {code:xml}
> <log4net>
> <appender name="LogFileAppenderXML" type="log4net.Appender.RollingFileAppender"> <file value="Logs\.xml" />
> <datePattern value="yyyy-MM-dd-'Xyz'" />
> <appendToFile value="true" />
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <rollingStyle value="Composite" />
> <maxSizeRollBackups value="40" />
> <maximumFileSize value="1MB" />
> <preserveLogFileNameExtension value="true" />
> <staticLogFileName value="true" />
> <layout type="log4net.Layout.XmlLayout"/>
> </appender>
> <root>
> <level value="ALL"/>
> <appender-ref ref="LogFileAppenderXML"></appender-ref>
> </root>
> </log4net>
> {code}
>
> With the above configuration, the rolling was working fine for a single run of the application, but after a restart of the logging manager (or the application), the previous rolled files are overwritten instead of new rolled files being created with the last highest rolled file index.
> +*Steps to reproduce:*+
> # Create an application [console or wpf] with the above log4net config
> # Start logging
> ## Until At least 10 rolled files are created
> # Close and ReStart the application
> # Start logging again
> ## Observe the rolled files
> ## Start logging and when the logging information reaches to maximumFileSize, {color:#172b4d}the previous rolled file content will be overwritten with new content, _*instead of increasing the rolled file count.*_{color}
> {color:#172b4d}Looked into the source code of *RollingFileAppender* found that {color}
> * {color:#172b4d}At the initial phase all the rolled file names, are converted into the *LowerInvariant and* passing to the *InitializeFromOneFile* method{color}
>
> {code:c#}
> private void InitializeRollBackups(string baseFile, ArrayList arrayFiles)
> {
> if (null != arrayFiles)
> {
> string baseFileLower = baseFile.ToLowerInvariant();
> foreach(string curFileName in arrayFiles)
> {
> InitializeFromOneFile(baseFileLower,curFileName.ToLowerInvariant());
> }
> }
> }
> {code}
> - Inside *InitializeFromOneFile*
> - The date variable is not converting to lower or while comparing the *curFileName with a prefix not using ignoreCase*
> - that is leading not to get last rolled file index
> {code:c#}
> if (!curFileName.StartsWith(prefix) || !curFileName.EndsWith(suffix))
> {
> LogLog.Debug(declaringType, "Ignoring file ["+curFileName+"]
> because it is from a different date period");
> return;
> }
> {code}
> Is there any possibility to use ignoreCase while comparing curFileName with the prefix
> {code:c#}
> if (!curFileName.StartsWith(prefix,true,CultureInfo.InvariantCulture) || !curFileName.EndsWith(suffix))
> {code}
>
> Or is there any reason not to _*use ignoreCase while comparing curFileName*_ with the _*prefix?*_
>
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)