Refactor: fixed spaces to be tabs in RollingFileAppender.cs
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/89d3820b Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/89d3820b Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/89d3820b Branch: refs/heads/feature/RollingFileAppender-NG Commit: 89d3820b17cb6287c0a1da4ce236a6c2eba741a3 Parents: c8e5130 Author: Dominik Psenner <dpsen...@apache.org> Authored: Thu Jul 27 17:38:34 2017 +0200 Committer: Dominik Psenner <dpsen...@apache.org> Committed: Thu Jul 27 17:38:34 2017 +0200 ---------------------------------------------------------------------- src/Appender/RollingFileAppender.cs | 330 +++++++++++++++---------------- 1 file changed, 165 insertions(+), 165 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/89d3820b/src/Appender/RollingFileAppender.cs ---------------------------------------------------------------------- diff --git a/src/Appender/RollingFileAppender.cs b/src/Appender/RollingFileAppender.cs index a56766b..fcdd13a 100644 --- a/src/Appender/RollingFileAppender.cs +++ b/src/Appender/RollingFileAppender.cs @@ -124,10 +124,10 @@ namespace log4net.Appender /// <author>Douglas de la Torre</author> /// <author>Edward Smit</author> public class RollingFileAppender : FileAppender - { - #region Public Enums + { + #region Public Enums - /// <summary> + /// <summary> /// Style of rolling to use /// </summary> /// <remarks> @@ -259,7 +259,7 @@ namespace log4net.Appender #region Public Instance Properties #if !NET_1_0 && !CLI_1_0 && !NETCF - /// <summary> + /// <summary> /// Gets or sets the strategy for determining the current date and time. The default /// implementation is to use LocalDateTime which internally calls through to DateTime.Now. /// DateTime.UtcNow may be used on frameworks newer than .NET 1.0 by specifying @@ -272,17 +272,17 @@ namespace log4net.Appender /// <para> /// Gets or sets the <see cref="RollingFileAppender.IDateTime"/> used to return the current date and time. /// </para> - /// <para> - /// There are two built strategies for determining the current date and time, + /// <para> + /// There are two built strategies for determining the current date and time, /// <see cref="RollingFileAppender.LocalDateTime"/> - /// and <see cref="RollingFileAppender.UniversalDateTime"/>. - /// </para> - /// <para> + /// and <see cref="RollingFileAppender.UniversalDateTime"/>. + /// </para> + /// <para> /// The default strategy is <see cref="RollingFileAppender.LocalDateTime"/>. /// </para> /// </remarks> #else - /// <summary> + /// <summary> /// Gets or sets the strategy for determining the current date and time. The default /// implementation is to use LocalDateTime which internally calls through to DateTime.Now. /// </summary> @@ -293,12 +293,12 @@ namespace log4net.Appender /// <para> /// Gets or sets the <see cref="RollingFileAppender.IDateTime"/> used to return the current date and time. /// </para> - /// <para> + /// <para> /// The default strategy is <see cref="RollingFileAppender.LocalDateTime"/>. /// </para> /// </remarks> #endif - public IDateTime DateTimeStrategy + public IDateTime DateTimeStrategy { get { return m_dateTime; } set { m_dateTime = value; } @@ -491,25 +491,25 @@ namespace log4net.Appender } } - /// <summary> - /// Gets or sets a value indicating whether to preserve the file name extension when rolling. - /// </summary> - /// <value> - /// <c>true</c> if the file name extension should be preserved. - /// </value> - /// <remarks> - /// <para> - /// By default file.log is rolled to file.log.yyyy-MM-dd or file.log.curSizeRollBackup. - /// However, under Windows the new file name will loose any program associations as the - /// extension is changed. Optionally file.log can be renamed to file.yyyy-MM-dd.log or - /// file.curSizeRollBackup.log to maintain any program associations. - /// </para> - /// </remarks> - public bool PreserveLogFileNameExtension - { - get { return m_preserveLogFileNameExtension; } - set { m_preserveLogFileNameExtension = value; } - } + /// <summary> + /// Gets or sets a value indicating whether to preserve the file name extension when rolling. + /// </summary> + /// <value> + /// <c>true</c> if the file name extension should be preserved. + /// </value> + /// <remarks> + /// <para> + /// By default file.log is rolled to file.log.yyyy-MM-dd or file.log.curSizeRollBackup. + /// However, under Windows the new file name will loose any program associations as the + /// extension is changed. Optionally file.log can be renamed to file.yyyy-MM-dd.log or + /// file.curSizeRollBackup.log to maintain any program associations. + /// </para> + /// </remarks> + public bool PreserveLogFileNameExtension + { + get { return m_preserveLogFileNameExtension; } + set { m_preserveLogFileNameExtension = value; } + } /// <summary> /// Gets or sets a value indicating whether to always log to @@ -538,18 +538,18 @@ namespace log4net.Appender #endregion Public Instance Properties - #region Private Static Fields + #region Private Static Fields - /// <summary> - /// The fully qualified type of the RollingFileAppender class. - /// </summary> - /// <remarks> - /// Used by the internal logger to record the Type of the - /// log message. - /// </remarks> - private readonly static Type declaringType = typeof(RollingFileAppender); + /// <summary> + /// The fully qualified type of the RollingFileAppender class. + /// </summary> + /// <remarks> + /// Used by the internal logger to record the Type of the + /// log message. + /// </remarks> + private readonly static Type declaringType = typeof(RollingFileAppender); - #endregion Private Static Fields + #endregion Private Static Fields #region Override implementation of FileAppender @@ -582,7 +582,7 @@ namespace log4net.Appender base.Append(loggingEvent); } - /// <summary> + /// <summary> /// Write out an array of logging events. /// </summary> /// <param name="loggingEvents">the events to write to file.</param> @@ -729,12 +729,12 @@ namespace log4net.Appender if (m_rollDate) { - fileName = CombinePath(fileName, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo)); + fileName = CombinePath(fileName, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo)); } if (m_countDirection >= 0) { - fileName = CombinePath(fileName, "." + m_curSizeRollBackups); + fileName = CombinePath(fileName, "." + m_curSizeRollBackups); } } @@ -775,14 +775,14 @@ namespace log4net.Appender /// <returns></returns> private string GetWildcardPatternForFile(string baseFileName) { - if (m_preserveLogFileNameExtension) - { - return Path.GetFileNameWithoutExtension(baseFileName) + "*" + Path.GetExtension(baseFileName); - } - else - { - return baseFileName + '*'; - } + if (m_preserveLogFileNameExtension) + { + return Path.GetFileNameWithoutExtension(baseFileName) + "*" + Path.GetExtension(baseFileName); + } + else + { + return baseFileName + '*'; + } } /// <summary> @@ -837,7 +837,7 @@ namespace log4net.Appender DateTime last; using(SecurityContext.Impersonate(this)) { #if !NET_1_0 && !CLI_1_0 && !NETCF - if (DateTimeStrategy is UniversalDateTime) + if (DateTimeStrategy is UniversalDateTime) { last = System.IO.File.GetLastWriteTimeUtc(m_baseFileName); } @@ -846,9 +846,9 @@ namespace log4net.Appender #endif last = System.IO.File.GetLastWriteTime(m_baseFileName); #if !NET_1_0 && !CLI_1_0 && !NETCF - } + } #endif - } + } LogLog.Debug(declaringType, "["+last.ToString(m_datePattern,System.Globalization.DateTimeFormatInfo.InvariantInfo)+"] vs. ["+m_now.ToString(m_datePattern,System.Globalization.DateTimeFormatInfo.InvariantInfo)+"]"); if (!(last.ToString(m_datePattern,System.Globalization.DateTimeFormatInfo.InvariantInfo).Equals(m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo)))) @@ -918,7 +918,7 @@ namespace log4net.Appender /// <param name="curFileName"></param> private void InitializeFromOneFile(string baseFile, string curFileName) { - if (curFileName.StartsWith(Path.GetFileNameWithoutExtension(baseFile)) == false) + if (curFileName.StartsWith(Path.GetFileNameWithoutExtension(baseFile)) == false) { // This is not a log file, so ignore return; @@ -929,7 +929,7 @@ namespace log4net.Appender return; } - /* + /* if (m_staticLogFileName) { int endLength = curFileName.Length - index; @@ -939,7 +939,7 @@ namespace log4net.Appender return; } } - */ + */ // Only look for files in the current roll point if (m_rollDate && !m_staticLogFileName) @@ -957,42 +957,42 @@ namespace log4net.Appender try { // Bump the counter up to the highest count seen so far - int backup = GetBackUpIndex(curFileName); - - // caution: we might get a false positive when certain - // date patterns such as yyyyMMdd are used...those are - // valid number but aren't the kind of back up index - // we're looking for - if (backup > m_curSizeRollBackups) - { - if (0 == m_maxSizeRollBackups) - { - // Stay at zero when zero backups are desired - } - else if (-1 == m_maxSizeRollBackups) - { - // Infinite backups, so go as high as the highest value - m_curSizeRollBackups = backup; - } - else - { - // Backups limited to a finite number - if (m_countDirection >= 0) - { - // Go with the highest file when counting up - m_curSizeRollBackups = backup; - } - else - { - // Clip to the limit when counting down - if (backup <= m_maxSizeRollBackups) - { - m_curSizeRollBackups = backup; - } - } - } - LogLog.Debug(declaringType, "File name [" + curFileName + "] moves current count to [" + m_curSizeRollBackups + "]"); - } + int backup = GetBackUpIndex(curFileName); + + // caution: we might get a false positive when certain + // date patterns such as yyyyMMdd are used...those are + // valid number but aren't the kind of back up index + // we're looking for + if (backup > m_curSizeRollBackups) + { + if (0 == m_maxSizeRollBackups) + { + // Stay at zero when zero backups are desired + } + else if (-1 == m_maxSizeRollBackups) + { + // Infinite backups, so go as high as the highest value + m_curSizeRollBackups = backup; + } + else + { + // Backups limited to a finite number + if (m_countDirection >= 0) + { + // Go with the highest file when counting up + m_curSizeRollBackups = backup; + } + else + { + // Clip to the limit when counting down + if (backup <= m_maxSizeRollBackups) + { + m_curSizeRollBackups = backup; + } + } + } + LogLog.Debug(declaringType, "File name [" + curFileName + "] moves current count to [" + m_curSizeRollBackups + "]"); + } } catch(FormatException) { @@ -1002,37 +1002,37 @@ namespace log4net.Appender } } - /// <summary> - /// Attempts to extract a number from the end of the file name that indicates - /// the number of the times the file has been rolled over. - /// </summary> - /// <remarks> - /// Certain date pattern extensions like yyyyMMdd will be parsed as valid backup indexes. - /// </remarks> - /// <param name="curFileName"></param> - /// <returns></returns> - private int GetBackUpIndex(string curFileName) - { - int backUpIndex = -1; - string fileName = curFileName; - - if (m_preserveLogFileNameExtension) - { - fileName = Path.GetFileNameWithoutExtension(fileName); - } - - int index = fileName.LastIndexOf("."); - if (index > 0) - { - // if the "yyyy-MM-dd" component of file.log.yyyy-MM-dd is passed to TryParse - // it will gracefully fail and return backUpIndex will be 0 - SystemInfo.TryParse(fileName.Substring(index + 1), out backUpIndex); - } - - return backUpIndex; - } - - /// <summary> + /// <summary> + /// Attempts to extract a number from the end of the file name that indicates + /// the number of the times the file has been rolled over. + /// </summary> + /// <remarks> + /// Certain date pattern extensions like yyyyMMdd will be parsed as valid backup indexes. + /// </remarks> + /// <param name="curFileName"></param> + /// <returns></returns> + private int GetBackUpIndex(string curFileName) + { + int backUpIndex = -1; + string fileName = curFileName; + + if (m_preserveLogFileNameExtension) + { + fileName = Path.GetFileNameWithoutExtension(fileName); + } + + int index = fileName.LastIndexOf("."); + if (index > 0) + { + // if the "yyyy-MM-dd" component of file.log.yyyy-MM-dd is passed to TryParse + // it will gracefully fail and return backUpIndex will be 0 + SystemInfo.TryParse(fileName.Substring(index + 1), out backUpIndex); + } + + return backUpIndex; + } + + /// <summary> /// Takes a list of files and a base file name, and looks for /// 'incremented' versions of the base file. Bumps the max /// count up to the highest count seen. @@ -1165,7 +1165,7 @@ namespace log4net.Appender if (m_rollDate && File != null && m_scheduledFilename == null) { - m_scheduledFilename = CombinePath(File, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo)); + m_scheduledFilename = CombinePath(File, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo)); } ExistingInit(); @@ -1177,24 +1177,24 @@ namespace log4net.Appender #region Roll File - /// <summary> - /// - /// </summary> - /// <param name="path1"></param> - /// <param name="path2">.1, .2, .3, etc.</param> - /// <returns></returns> - private string CombinePath(string path1, string path2) - { - string extension = Path.GetExtension(path1); - if (m_preserveLogFileNameExtension && extension.Length > 0) - { - return Path.Combine(Path.GetDirectoryName(path1), Path.GetFileNameWithoutExtension(path1) + path2 + extension); - } - else - { - return path1 + path2; - } - } + /// <summary> + /// + /// </summary> + /// <param name="path1"></param> + /// <param name="path2">.1, .2, .3, etc.</param> + /// <returns></returns> + private string CombinePath(string path1, string path2) + { + string extension = Path.GetExtension(path1); + if (m_preserveLogFileNameExtension && extension.Length > 0) + { + return Path.Combine(Path.GetDirectoryName(path1), Path.GetFileNameWithoutExtension(path1) + path2 + extension); + } + else + { + return path1 + path2; + } + } /// <summary> /// Rollover the file(s) to date/time tagged file(s). @@ -1222,9 +1222,9 @@ namespace log4net.Appender //something has gone wrong if we hit this -- we should only //roll over if the new file will be different from the old string dateFormat = m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo); - if (m_scheduledFilename.Equals(CombinePath(File, dateFormat))) + if (m_scheduledFilename.Equals(CombinePath(File, dateFormat))) { - ErrorHandler.Error("Compare " + m_scheduledFilename + " : " + CombinePath(File, dateFormat)); + ErrorHandler.Error("Compare " + m_scheduledFilename + " : " + CombinePath(File, dateFormat)); return; } @@ -1237,8 +1237,8 @@ namespace log4net.Appender //we may have to roll over a large number of backups here for (int i = 1; i <= m_curSizeRollBackups; i++) { - string from = CombinePath(File, "." + i); - string to = CombinePath(m_scheduledFilename, "." + i); + string from = CombinePath(File, "." + i); + string to = CombinePath(m_scheduledFilename, "." + i); RollFile(from, to); } @@ -1249,7 +1249,7 @@ namespace log4net.Appender m_curSizeRollBackups = 0; //new scheduled name - m_scheduledFilename = CombinePath(File, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo)); + m_scheduledFilename = CombinePath(File, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo)); if (fileIsOpen) { @@ -1458,20 +1458,20 @@ namespace log4net.Appender // Delete the oldest file, to keep Windows happy. if (m_curSizeRollBackups == m_maxSizeRollBackups) { - DeleteFile(CombinePath(baseFileName, "." + m_maxSizeRollBackups)); + DeleteFile(CombinePath(baseFileName, "." + m_maxSizeRollBackups)); m_curSizeRollBackups--; } // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} for (int i = m_curSizeRollBackups; i >= 1; i--) { - RollFile((CombinePath(baseFileName, "." + i)), (CombinePath(baseFileName, "." + (i + 1)))); + RollFile((CombinePath(baseFileName, "." + i)), (CombinePath(baseFileName, "." + (i + 1)))); } m_curSizeRollBackups++; // Rename fileName to fileName.1 - RollFile(baseFileName, CombinePath(baseFileName, ".1")); + RollFile(baseFileName, CombinePath(baseFileName, ".1")); } else { @@ -1493,34 +1493,34 @@ namespace log4net.Appender string archiveFileBaseName = baseFileName; if (!m_staticLogFileName) { - if (m_preserveLogFileNameExtension) - { - string extension = Path.GetExtension(archiveFileBaseName); - string baseName = Path.GetFileNameWithoutExtension(archiveFileBaseName); + if (m_preserveLogFileNameExtension) + { + string extension = Path.GetExtension(archiveFileBaseName); + string baseName = Path.GetFileNameWithoutExtension(archiveFileBaseName); int lastDotIndex = baseName.LastIndexOf("."); if (lastDotIndex >= 0) { archiveFileBaseName = baseName.Substring(0, lastDotIndex) + extension; } - } - else - { + } + else + { int lastDotIndex = archiveFileBaseName.LastIndexOf("."); if (lastDotIndex >= 0) { archiveFileBaseName = archiveFileBaseName.Substring(0, lastDotIndex); } - } + } } // Delete the archive file - DeleteFile(CombinePath(archiveFileBaseName, "." + oldestFileIndex)); + DeleteFile(CombinePath(archiveFileBaseName, "." + oldestFileIndex)); } if (m_staticLogFileName) { m_curSizeRollBackups++; - RollFile(baseFileName, CombinePath(baseFileName, "." + m_curSizeRollBackups)); + RollFile(baseFileName, CombinePath(baseFileName, "." + m_curSizeRollBackups)); } } } @@ -1691,7 +1691,7 @@ namespace log4net.Appender /// </summary> private bool m_staticLogFileName = true; - /// <summary> + /// <summary> /// Value indicating whether to preserve the file name extension when rolling. /// </summary> private bool m_preserveLogFileNameExtension = false; @@ -1765,7 +1765,7 @@ namespace log4net.Appender } #if !NET_1_0 && !CLI_1_0 && !NETCF - /// <summary> + /// <summary> /// Implementation of <see cref="IDateTime"/> that returns the current time as the coordinated universal time (UTC). /// </summary> private class UniversalDateTime : IDateTime @@ -1786,6 +1786,6 @@ namespace log4net.Appender } #endif - #endregion DateTime + #endregion DateTime } }