[
https://issues.apache.org/jira/browse/LOG4NET-378?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14103761#comment-14103761
]
Krzysztof L. commented on LOG4NET-378:
--------------------------------------
I have found another issue when using second appender configuration from my
previous note
(https://issues.apache.org/jira/browse/LOG4NET-378?focusedCommentId=14103641&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14103641)...
Problem from this ticket still occurs when using configuration like that:
{code:xml}
<appender name="mainAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\Module_XYZ_" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<encoding>utf-8</encoding>
<preserveLogFileNameExtension value="true"/>
<rollingStyle value="Composite" />
<datePattern value="''yyyy-MM-dd'.log'"/>
<maxSizeRollBackups value="10" />
<countDirection value="1"/>
<maximumFileSize value="30KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %-35logger - %message%newline" />
</layout>
</appender>
{code}
Problem does NOT occur if we change preserveLogFileNameExtension to false.
Problem has source in GetWildcardPatternForFile method from
RollingFileAppender.cs - currently it has following content:
{code}
private string GetWildcardPatternForFile(string baseFileName)
{
if (m_preserveLogFileNameExtension)
{
return Path.GetFileNameWithoutExtension(baseFileName) + ".*" +
Path.GetExtension(baseFileName);
}
else
{
return baseFileName + '*';
}
}
{code}
When we use file options which has NOT file extension (extension is defined in
datePattern) AND when we set preserveLogFileNameExtension to true:
{code:xml}
<file value="logs\Module_XYZ_" />
<preserveLogFileNameExtension value="true"/>
<datePattern value="''yyyy-MM-dd'.log'"/>
<rollingStyle value="Composite" />
{code}
then code from GetWildcardPatternForFile method will return e.g.:
{noformat}"Module_XYZ_.*"
{noformat}
So this is problem, because for this specific appender configuration it should
be something like this:
{noformat}"Module_XYZ_*"{noformat}
or maybe this:
{noformat}"Module_XYZ_*."{noformat}
In my test app. GetWildcardPatternForFile() is called for first time on
application start when logging system is initalizing (ActivateOptions() ->
ExistingInit() -> DetermineCurSizeRollBackups() -> GetWildcardPatternForFile())
- so it could be the case because GetWildcardPatternForFile() is called with
m_baseFileName which is set to e.g.
"C:\log4netTestMultithreaded\bin\Debug\logs\Module_XYZ_" (because base.File has
this value in ActivateOptions()) and on latter stage - when file is opened in
log4net.Appender.FileAppender.OpenFile()) base.File (m_fileName) - value is set
to e.g.
"C:\log4netTestMultithreaded\bin\Debug\logs\Module_XYZ_2014-08-20.0.LOG". Maybe
when GetWildcardPatternForFile() code was written it was used on later stage or
maybe case when in <file value=".." /> option no file extension is defined?
----
Another problem with above configuration is that option maxSizeRollBackups
Another is not working... Appender creates files with index higher than
maxSizeRollBackups...
I have found that problem is probably in RollOverRenameFiles method which
currently contains code like this:
{code}
if (m_countDirection < 0)
{
// (...)
}
else
{
// (...)
string archiveFileBaseName = baseFileName;
if (!m_staticLogFileName)
{
int lastDotIndex = (m_preserveLogFileNameExtension ?
Path.GetFileNameWithoutExtension(archiveFileBaseName) :
archiveFileBaseName).LastIndexOf(".");
if (lastDotIndex >= 0)
{
archiveFileBaseName = archiveFileBaseName.Substring(0,
lastDotIndex);
}
}
// Delete the archive file
DeleteFile(CombinePath(archiveFileBaseName, "." + oldestFileIndex));
// (...)
}
{code}
For my specific appender configuration archiveFileBaseName is e.g.
"C:\log4netTestMultithreaded\bin\Debug\logs\Module_XYZ_2014-08-20.5.LOG" (due
to preserveLogFileNameExtension = true setting file name ends with "5.log" and
not "log.5")...
So code in RollOverRenameFiles method should be corrected to take account of
such a case...
----
Should I create new tickets for this cases or maybe it should be resolved in
the context of this LOG4NET-378 ticket?
> Rolling log file is overwritten when application is restarted
> -------------------------------------------------------------
>
> Key: LOG4NET-378
> URL: https://issues.apache.org/jira/browse/LOG4NET-378
> Project: Log4net
> Issue Type: Bug
> Components: Appenders
> Affects Versions: 1.2.11
> Reporter: Horst Beham
> Assignee: Dominik Psenner
> Priority: Critical
> Fix For: 1.2.12
>
>
> My server process uses log files which roll on date and file size (4MB).
> When I restart the server and there are already more than 1 log files for the
> current date, the 2nd segment gets overwritten and the 3rd, 4th, ... may get
> overwritten later, when #2 is filled up again.
> I'm using version 1.2.11, which I can't select in the "Affects Version" combo
> box.
> e.g.
> flotto.20130527.0.log = 4MB
> flotto.20130527.1.log = 0MB (just got overwritten when the server was
> restarted)
> flotto.20130527.2.log = 4MB (still contains original data but will be
> overwritten too as soon as #1 fills up)
> flotto.20130527.3.log = 4MB (same as above)
> The configuration in MyServer.exe.config looks like this:
> <log4net>
> <appender name="LogFileAppender"
> type="log4net.Appender.RollingFileAppender">
> <file value="flotto.log" />
> <appendToFile value="true" />
> <encoding>utf-8</encoding>
> <preserveLogFileNameExtension value="true"/>
> <rollingStyle value="Composite" />
> <staticLogFileName value="false" />
> <datePattern value=".yyyyMMdd"/>
> <countDirection value="1"/>
> <maximumFileSize value="4MB" />
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date [%-7thread] %-5level %-35logger -
> %message%newline" />
> </layout>
> </appender>
> <root>
> <level value="INFO" />
> <appender-ref ref="LogFileAppender"/>
> </root>
> <logger name="Flotto.FlottoService">
> <!--<level value="DEBUG"/>-->
> </logger>
> <logger name="Flotto.TcpServer">
> <!--<level value="DEBUG"/>-->
> </logger>
> <logger name="Flotto.UdpBroadcastReceiver">
> <!--<level value="DEBUG"/>-->
> </logger>
> <logger name="Flotto.GpsTrackerGprsServer">
> <level value="DEBUG"/>
> </logger>
> <logger name="Flotto.SmsAtHttpReceiver">
> <level value="DEBUG"/>
> </logger>
> <logger name="Flotto.SmsAtHttpSender">
> <level value="DEBUG"/>
> </logger>
> <logger name="Flotto.BulksmsComHttpReceiver">
> <level value="DEBUG"/>
> </logger>
> <logger name="Flotto.BulksmsComHttpSender">
> <level value="DEBUG"/>
> </logger>
> <logger name="Flotto.TrackerManager">
> <!--<level value="INFO"/>-->
> </logger>
> </log4net>
--
This message was sent by Atlassian JIRA
(v6.2#6252)