You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by bo...@apache.org on 2017/05/01 13:16:46 UTC
logging-log4net git commit: add unit test for PR #23
Repository: logging-log4net
Updated Branches:
refs/heads/PR_23 ce481db1b -> f8b729006
add unit test for PR #23
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/f8b72900
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/f8b72900
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/f8b72900
Branch: refs/heads/PR_23
Commit: f8b7290065f16c7fce5b54a2d2c348b16e20ab4e
Parents: ce481db
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon May 1 15:15:53 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon May 1 15:16:32 2017 +0200
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 56 +++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/f8b72900/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index 6819ec2..6704777 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -146,7 +146,16 @@ namespace log4net.Tests.Appender
/// <param name="iExpectedCount"></param>
private static void VerifyFileCount(int iExpectedCount)
{
- ArrayList alFiles = GetExistingFiles(c_fileName);
+ VerifyFileCount(iExpectedCount, false);
+ }
+ /// <summary>
+ /// Finds the number of files that match the base file name,
+ /// and matches the result against an expected count
+ /// </summary>
+ /// <param name="iExpectedCount"></param>
+ private static void VerifyFileCount(int iExpectedCount, bool preserveLogFileNameExtension)
+ {
+ ArrayList alFiles = GetExistingFiles(c_fileName, preserveLogFileNameExtension);
Assert.IsNotNull(alFiles);
Assert.AreEqual(iExpectedCount, alFiles.Count);
}
@@ -192,12 +201,52 @@ namespace log4net.Tests.Appender
VerifyFileCount(2);
}
+ [Test]
+ public void RollingCombinedWithPreserveExtension()
+ {
+ _root = ((Repository.Hierarchy.Hierarchy)Utils.GetRepository()).Root;
+ _root.Level = Level.All;
+ PatternLayout patternLayout = new PatternLayout();
+ patternLayout.ActivateOptions();
+
+ RollingFileAppender roller = new RollingFileAppender();
+ roller.StaticLogFileName = false;
+ roller.Layout = patternLayout;
+ roller.AppendToFile = true;
+ roller.RollingStyle = RollingFileAppender.RollingMode.Composite;
+ roller.DatePattern = "dd_MM_yyyy";
+ roller.MaxSizeRollBackups = 1;
+ roller.CountDirection = 1;
+ roller.PreserveLogFileNameExtension = true;
+ roller.MaximumFileSize = "10KB";
+ roller.File = c_fileName;
+ roller.ActivateOptions();
+ _root.AddAppender(roller);
+
+ _root.Repository.Configured = true;
+
+ for (int i = 0; i < 1000; i++)
+ {
+ StringBuilder s = new StringBuilder();
+ for (int j = 50; j < 100; j++)
+ {
+ if (j > 50) {
+ s.Append(" ");
+ }
+ s.Append(j);
+ }
+ _root.Log(Level.Debug, s.ToString(), null);
+ }
+ VerifyFileCount(2, true);
+ }
+
/// <summary>
/// Removes all test files that exist
/// </summary>
private static void DeleteTestFiles()
{
ArrayList alFiles = GetExistingFiles(c_fileName);
+ alFiles.AddRange(GetExistingFiles(c_fileName, true));
foreach(string sFile in alFiles)
{
try
@@ -1938,7 +1987,12 @@ namespace log4net.Tests.Appender
private static ArrayList GetExistingFiles(string baseFilePath)
{
+ return GetExistingFiles(baseFilePath, false);
+ }
+ private static ArrayList GetExistingFiles(string baseFilePath, bool preserveLogFileNameExtension)
+ {
RollingFileAppender appender = new RollingFileAppender();
+ appender.PreserveLogFileNameExtension = preserveLogFileNameExtension;
appender.SecurityContext = NullSecurityContext.Instance;
return (ArrayList)Utils.InvokeMethod(appender, "GetExistingFiles", baseFilePath);