Modified:
logging/log4net/trunk/tests/src/Appender/RollingFileAppender
Test.cs
URL: http://svn.apache.org/v
iewvc/logging/log4net/trunk/tests/src/Appender/RollingFileAp
penderTest.cs?view=diff&rev=511537&r1=511536&r2=
511537
============================================================
==================
---
logging/log4net/trunk/tests/src/Appender/RollingFileAppender
Test.cs (original)
+++
logging/log4net/trunk/tests/src/Appender/RollingFileAppender
Test.cs Sun Feb 25 08:14:29 2007
 -19,46
+19,62 
using System;
using System.Collections;
+using System.Diagnostics;
using System.IO;
+using System.Text;
using System.Text.RegularExpressions;
-using log4net.Layout;
+using log4net.Appender;
using log4net.Core;
+using log4net.Layout;
+using log4net.Repository.Hierarchy;
+using log4net.Util;
using NUnit.Framework;
-using log4net.Repository.Hierarchy;
-using log4net.Appender;
namespace log4net.Tests.Appender
{
/// <summary>
/// Used for internal unit testing the <see
cref="RollingFileAppender"/> class.
/// </summary>
- [TestFixture] public class RollingFileAppenderTest
+ [TestFixture]
+ public class RollingFileAppenderTest
{
- const string _fileName =
"test_41d3d834_4320f4da.log";
- const string _testMessage =
"012345678901234567890123456789012345678901234567890123
45678901234567890123456789012345678901234567";
- const int _iMaximumFileSize = 450; // in bytes
- int _iMessagesLoggedThisFile = 0;
- int _iMessagesLogged = 0;
- int _iCountDirection = 0;
- int _MaxSizeRollBackups = 3;
- CountingAppender _caRoot;
- Logger _root;
+ private const string c_fileName =
"test_41d3d834_4320f4da.log";
+ private const string c_testMessage =
"012345678901234567890123456789012345678901234567890123
45678901234567890123456789012345678901234567";
+ private const int c_iMaximumFileSize = 450; // in bytes
+ private int _iMessagesLoggedThisFile = 0;
+ private int _iMessagesLogged = 0;
+ private int _iCountDirection = 0;
+ private int _MaxSizeRollBackups = 3;
+ private CountingAppender _caRoot;
+ private Logger _root;
private class SilentErrorHandler : IErrorHandler
{
- System.Text.StringBuilder m_buffer=new
System.Text.StringBuilder();
+ private StringBuilder m_buffer = new StringBuilder();
public string Message
{
- get {return m_buffer.ToString();}
+ get { return m_buffer.ToString(); }
+ }
+
+ public void Error(string message)
+ {
+ m_buffer.Append(message + "n");
+ }
+
+ public void Error(string message, Exception e)
+ {
+ m_buffer.Append(message + "n" + e.Message +
"n");
}
- public void Error(string
message) {m_buffer.Append(message+"n");}
- public void Error(string message, Exception
e) {m_buffer.Append(message+"n"+e.Message+&q
uot;n");}
- public void Error(string message, Exception e, ErrorCode
errorCode) {m_buffer.Append(message+"n"+e.Message
+"n");}
+ public void Error(string message, Exception e, ErrorCode
errorCode)
+ {
+ m_buffer.Append(message + "n" + e.Message +
"n");
+ }
}
+
/// <summary>
/// Sets up variables used for the tests
/// </summary>
 -66,7
+82,7 
{
_iMessagesLoggedThisFile = 0;
_iMessagesLogged = 0;
- _iCountDirection = +1; // Up
+ _iCountDirection = +1; // Up
_MaxSizeRollBackups = 3;
}
 -75,12
+91,12 
/// with all appenders, and deletes any test files used
/// for logging.
/// </summary>
- private void ResetAndDeleteTestFiles()
+ private static void ResetAndDeleteTestFiles()
{
// Regular users should not use the clear method
lightly!
LogManager.GetRepository().ResetConfiguration();
LogManager.GetRepository().Shutdown();
- ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetR
epository()).Clear();
+ ((Repository.Hierarchy.Hierarchy)LogManager.GetRepositor
y()).Clear();
DeleteTestFiles();
}
 -89,7
+105,8 
/// Any initialization that happens before each test can
/// go here
/// </summary>
- [SetUp] public void SetUp()
+ [SetUp]
+ public void SetUp()
{
ResetAndDeleteTestFiles();
InitializeVariables();
 -98,7
+115,8 
/// <summary>
/// Any steps that happen after each test go here
/// </summary>
- [TearDown] public void TearDown()
+ [TearDown]
+ public void TearDown()
{
ResetAndDeleteTestFiles();
}
 -108,9
+126,9 
/// and matches the result against an expected count
/// </summary>
/// <param
name="iExpectedCount"></param>
- private void VerifyFileCount( int iExpectedCount )
+ private static void VerifyFileCount(int iExpectedCount)
{
- ArrayList alFiles = GetExistingFiles(_fileName);
+ ArrayList alFiles = GetExistingFiles(c_fileName);
Assert.IsNotNull(alFiles);
Assert.AreEqual(iExpectedCount, alFiles.Count);
}
 -119,12
+137,12 
/// Creates a file with the given number, and the shared
base file name
/// </summary>
/// <param
name="iFileNumber"></param>
- private void CreateFile( int iFileNumber )
+ private static void CreateFile(int iFileNumber)
{
- FileInfo fileInfo = new FileInfo(
MakeFileName(_fileName, iFileNumber) );
+ FileInfo fileInfo = new
FileInfo(MakeFileName(c_fileName, iFileNumber));
FileStream fileStream = null;
- try
+ try
{
fileStream = fileInfo.Create();
}
 -135,17
+153,19 
try
{
fileStream.Close();
- }
- catch {}
+ }
+ catch
+ {
+ }
}
- fileStream = null;
}
}
/// <summary>
/// Verifies that the code correctly loads all filenames
/// </summary>
- [Test] public void TestGetExistingFiles()
+ [Test]
+ public void TestGetExistingFiles()
{
VerifyFileCount(0);
CreateFile(0);
 -157,32
+177,32 
/// <summary>
/// Removes all test files that exist
/// </summary>
- private void DeleteTestFiles()
+ private static void DeleteTestFiles()
{
- ArrayList alFiles = GetExistingFiles(_fileName);
+ ArrayList alFiles = GetExistingFiles(c_fileName);
foreach(string sFile in alFiles)
{
try
{
- System.Diagnostics.Debug.WriteLine("Deleting test
file " + sFile);
- System.IO.File.Delete(sFile);
- }
- catch (Exception ex)
+ Debug.WriteLine("Deleting test file " +
sFile);
+ File.Delete(sFile);
+ }
+ catch(Exception ex)
{
- System.Diagnostics.Debug.WriteLine("Exception
while deleting test file " + ex.ToString());
+ Debug.WriteLine("Exception while deleting test
file " + ex);
}
}
}
- /// <summary>
- /// Generates a file name associated with the count.
- /// </summary>
- /// <param
name="iFileCount"></param>
- /// <returns></returns>
- private string MakeFileName(int iFileCount)
- {
- return MakeFileName(_fileName, iFileCount);
- }
+ ///// <summary>
+ ///// Generates a file name associated with the count.
+ ///// </summary>
+ ///// <param
name="iFileCount"></param>
+ ///// <returns></returns>
+ //private string MakeFileName(int iFileCount)
+ //{
+ // return MakeFileName(_fileName, iFileCount);
+ //}
/// <summary>
/// Generates a file name associated with the count,
using
 -191,12
+211,12 
/// <param
name="sBaseFile"></param>
/// <param
name="iFileCount"></param>
/// <returns></returns>
- private string MakeFileName(string sBaseFile, int
iFileCount)
+ private static string MakeFileName(string sBaseFile, int
iFileCount)
{
- if (0 == iFileCount)
+ if (0 == iFileCount)
{
return sBaseFile;
- }
+ }
return sBaseFile + "." + iFileCount;
}
 -228,14
+248,14 
// Create the new appender
//
RollingFileAppender appender = new
RollingFileAppender();
- appender.Layout = layout;
- appender.File = _fileName;
- appender.MaximumFileSize =
_iMaximumFileSize.ToString();
- appender.MaxSizeRollBackups = _MaxSizeRollBackups;
- appender.CountDirection = _iCountDirection;
- appender.RollingStyle =
RollingFileAppender.RollingMode.Size;
- appender.LockingModel =lockModel;
-
+ appender.Layout = layout;
+ appender.File = c_fileName;
+ appender.MaximumFileSize =
c_iMaximumFileSize.ToString();
+ appender.MaxSizeRollBackups = _MaxSizeRollBackups;
+ appender.CountDirection = _iCountDirection;
+ appender.RollingStyle =
RollingFileAppender.RollingMode.Size;
+ appender.LockingModel = lockModel;
+
appender.ActivateOptions();
return appender;
 -260,7
+280,9 
/// <summary>
/// Default constructor
/// </summary>
- public RollFileEntry() {}
+ public RollFileEntry()
+ {
+ }
/// <summary>
/// Constructor used when the fileInfo and expected
length are known
 -269,7
+291,7 
/// <param
name="fileLength"></param>
public RollFileEntry(string fileName, long fileLength)
{
- m_fileName = fileName;
+ m_fileName = fileName;
m_fileLength = fileLength;
}
 -280,7
+302,7 
{
get { return m_fileName; }
}
-
+
/// <summary>
/// The expected length of the file
/// </summary>
 -313,9
+335,9 
/// </summary>
/// <param
name="preLogFileEntries"></param>
/// <param
name="postLogFileEntries"></param>
- public RollConditions( RollFileEntry[]
preLogFileEntries, RollFileEntry[] postLogFileEntries )
+ public RollConditions(RollFileEntry[] preLogFileEntries,
RollFileEntry[] postLogFileEntries)
{
- m_preLogFileEntries = preLogFileEntries;
+ m_preLogFileEntries = preLogFileEntries;
m_postLogFileEntries = postLogFileEntries;
}
 -338,12
+360,12 
}
}
- private void VerifyExistenceAndRemoveFromList( ArrayList
alExisting, string sFileName, FileInfo file, RollFileEntry
entry )
+ private static void
VerifyExistenceAndRemoveFromList(ArrayList alExisting,
string sFileName, FileInfo file, RollFileEntry entry)
{
- Assert.IsTrue(alExisting.Contains( sFileName ),
"filename not found in test directory",
sFileName);
+ Assert.IsTrue(alExisting.Contains(sFileName),
"filename not found in test directory",
sFileName);
Assert.AreEqual(entry.FileLength, file.Length,
"file length mismatch");
// Remove this file from the list
- alExisting.Remove( sFileName );
+ alExisting.Remove(sFileName);
}
/// <summary>
 -352,30
+374,30 
/// </summary>
/// <param
name="sBaseFileName"></param>
/// <param
name="fileEntries"></param>
- private void VerifyFileConditions( string sBaseFileName,
RollFileEntry[] fileEntries )
+ private static void VerifyFileConditions(string
sBaseFileName, RollFileEntry[] fileEntries)
{
- ArrayList alExisting = GetExistingFiles( sBaseFileName
);
- if (null != fileEntries )
+ ArrayList alExisting = GetExistingFiles(sBaseFileName);
+ if (null != fileEntries)
{
// AssertEquals( "File count mismatch",
alExisting.Count, fileEntries.Length );
- foreach( RollFileEntry rollFile in fileEntries )
+ foreach(RollFileEntry rollFile in fileEntries)
{
string sFileName = rollFile.FileName;
FileInfo file = new FileInfo(sFileName);
- if (rollFile.FileLength > 0 )
+ if (rollFile.FileLength > 0)
{
- Assert.IsTrue(file.Exists, "filename does
not exist", sFileName );
- VerifyExistenceAndRemoveFromList( alExisting,
sFileName, file, rollFile );
+ Assert.IsTrue(file.Exists, "filename does
not exist", sFileName);
+ VerifyExistenceAndRemoveFromList(alExisting,
sFileName, file, rollFile);
}
else
{
// If length is 0, file may not exist yet. If file
exists, make sure length
// is zero. If file doesn't exist, this is OK
- if (file.Exists )
+ if (file.Exists)
{
- VerifyExistenceAndRemoveFromList( alExisting,
sFileName, file, rollFile );
+ VerifyExistenceAndRemoveFromList(alExisting,
sFileName, file, rollFile);
}
}
}
 -397,9
+419,9 
/// </summary>
/// <param
name="sBaseFileName"></param>
/// <param name="entry"></param>
- private void VerifyPreConditions( string sBaseFileName,
RollConditions entry )
+ private static void VerifyPreConditions(string
sBaseFileName, RollConditions entry)
{
- VerifyFileConditions( sBaseFileName,
entry.GetPreLogFileEntries() );
+ VerifyFileConditions(sBaseFileName,
entry.GetPreLogFileEntries());
}
/// <summary>
 -409,9
+431,9 
/// </summary>
/// <param
name="sBaseFileName"></param>
/// <param name="entry"></param>
- private void VerifyPostConditions( string sBaseFileName,
RollConditions entry )
+ private static void VerifyPostConditions(string
sBaseFileName, RollConditions entry)
{
- VerifyFileConditions( sBaseFileName,
entry.GetPostLogFileEntries() );
+ VerifyFileConditions(sBaseFileName,
entry.GetPostLogFileEntries());
}
/// <summary>
 -420,34
+442,34 
/// </summary>
/// <param name="entry"></param>
/// <param
name="sMessageToLog"></param>
- private void LogMessage( RollConditions entry, string
sMessageToLog )
+ private void LogMessage(RollConditions entry, string
sMessageToLog)
{
Assert.AreEqual(_caRoot.Counter, _iMessagesLogged++);
_root.Log(Level.Debug, sMessageToLog, null);
- Assert.AreEqual(_caRoot.Counter, _iMessagesLogged);
+ Assert.AreEqual(_caRoot.Counter, _iMessagesLogged);
_iMessagesLoggedThisFile++;
}
- private void DumpFileEntry( RollFileEntry entry )
- {
- System.Diagnostics.Debug.WriteLine( "tfile name:
" + entry.FileName );
- System.Diagnostics.Debug.WriteLine( "tfile length:
" + entry.FileLength );
- }
-
- private void DumpTableEntry( RollConditions entry )
- {
- System.Diagnostics.Debug.WriteLine(
"Pre-Conditions" );
- foreach( RollFileEntry file in
entry.GetPreLogFileEntries() )
- {
- DumpFileEntry( file );
- }
- System.Diagnostics.Debug.WriteLine(
"Post-Conditions" );
- foreach( RollFileEntry file in
entry.GetPostLogFileEntries() )
- {
- DumpFileEntry( file );
- }
- // System.Diagnostics.Debug.WriteLine("");
- }
+ //private void DumpFileEntry( RollFileEntry entry )
+ //{
+ // System.Diagnostics.Debug.WriteLine( "tfile
name: " + entry.FileName );
+ // System.Diagnostics.Debug.WriteLine( "tfile
length: " + entry.FileLength );
+ //}
+
+ //private void DumpTableEntry( RollConditions entry )
+ //{
+ // System.Diagnostics.Debug.WriteLine(
"Pre-Conditions" );
+ // foreach( RollFileEntry file in
entry.GetPreLogFileEntries() )
+ // {
+ // DumpFileEntry( file );
+ // }
+ // System.Diagnostics.Debug.WriteLine(
"Post-Conditions" );
+ // foreach( RollFileEntry file in
entry.GetPostLogFileEntries() )
+ // {
+ // DumpFileEntry( file );
+ // }
+ //
// System.Diagnostics.Debug.WriteLine("");
+ //}
/// <summary>
/// Runs through all table entries, logging messages.
Before each message is logged,
 -457,20
+479,20 
/// <param
name="sBaseFileName"></param>
/// <param name="entries"></param>
/// <param
name="sMessageToLog"></param>
- private void RollFromTableEntries( string sBaseFileName,
RollConditions[] entries, string sMessageToLog )
+ private void RollFromTableEntries(string sBaseFileName,
RollConditions[] entries, string sMessageToLog)
{
- for( int i=0; i<entries.Length; i++ )
+ for(int i = 0; i < entries.Length; i++)
{
RollConditions entry = entries[i];
// System.Diagnostics.Debug.WriteLine( i + ":
Entry " + i + " pre/post conditions");
// DumpTableEntry( entry );
// System.Diagnostics.Debug.WriteLine( i + ":
Testing entry pre-conditions");
- VerifyPreConditions( sBaseFileName, entry );
+ VerifyPreConditions(sBaseFileName, entry);
// System.Diagnostics.Debug.WriteLine( i + ":
Logging message");
- LogMessage( entry, sMessageToLog );
+ LogMessage(entry, sMessageToLog);
// System.Diagnostics.Debug.WriteLine( i + ":
Testing entry post-conditions");
- VerifyPostConditions( sBaseFileName, entry );
+ VerifyPostConditions(sBaseFileName, entry);
// System.Diagnostics.Debug.WriteLine( i + ":
Finished validating entryn");
}
}
 -481,28
+503,28 
/// </summary>
/// <param
name="sMessage"></param>
/// <returns></returns>
- private int TotalMessageLength( string sMessage )
+ private static int TotalMessageLength(string sMessage)
{
const int iLengthCRLF = 2;
return sMessage.Length + iLengthCRLF;
}
-
+
/// <summary>
/// Determines how many messages of a fixed length can be
logged
/// to a single file before the file rolls.
/// </summary>
/// <param
name="iMessageLength"></param>
/// <returns></returns>
- private int MessagesPerFile( int iMessageLength )
+ private static int MessagesPerFile(int iMessageLength)
{
- int iMessagesPerFile = _iMaximumFileSize /
iMessageLength;
-
+ int iMessagesPerFile = c_iMaximumFileSize /
iMessageLength;
+
//
// RollingFileAppender checks for wrap BEFORE logging,
// so we will actually get one more message per file
than
// we would otherwise.
//
- if (iMessagesPerFile * iMessageLength <
_iMaximumFileSize )
+ if (iMessagesPerFile * iMessageLength <
c_iMaximumFileSize)
{
iMessagesPerFile++;
}
 -514,11
+536,11 
/// Determines the name of the current file
/// </summary>
/// <returns></returns>
- private string GetCurrentFile()
+ private static string GetCurrentFile()
{
// Current file name is always the base file name when
// counting. Dates will need a different approach
- return _fileName;
+ return c_fileName;
}
/// <summary>
 -529,18
+551,18 
/// <param
name="sBackupGroup"></param>
/// <param
name="iBackupFileLength"></param>
/// <returns></returns>
- private RollFileEntry[]
MakeBackupFileEntriesFromBackupGroup( string sBackupGroup,
int iBackupFileLength )
+ private static RollFileEntry[]
MakeBackupFileEntriesFromBackupGroup(string sBackupGroup,
int iBackupFileLength)
{
- string[] sFiles = sBackupGroup.Split( ' ' );
+ string[] sFiles = sBackupGroup.Split(' ');
ArrayList alEntries = new ArrayList();
- for( int i=0; i<sFiles.Length; i++ )
+ for(int i = 0; i < sFiles.Length; i++)
{
// Weed out any whitespace entries from the array
- if (sFiles[i].Trim().Length > 0 )
+ if (sFiles[i].Trim().Length > 0)
{
- alEntries.Add( new RollFileEntry( sFiles[i],
iBackupFileLength ) );
+ alEntries.Add(new RollFileEntry(sFiles[i],
iBackupFileLength));
}
}
 -553,45
+575,45 
/// <param
name="sBackupGroups"></param>
/// <param name="iGroup"></param>
/// <returns></returns>
- private string GetBackupGroup( string sBackupGroups, int
iGroup )
+ private static string GetBackupGroup(string
sBackupGroups, int iGroup)
{
- string[] sGroups = sBackupGroups.Split( ',' );
+ string[] sGroups = sBackupGroups.Split(',');
return sGroups[iGroup];
}
- /// <summary>
- /// Builds a collection of file entries based on the file
names
- /// specified in a groups string and the max file size
from the
- /// stats object
- /// </summary>
- /// <param
name="sBackupGroups"></param>
- /// <param name="stats"></param>
- /// <returns></returns>
- private RollFileEntry[]
MakeBackupFileEntriesForPreCondition( string sBackupGroups,
RollingStats stats )
- {
- if (0 == stats.NumberOfFileRolls )
- {
- return null; // first round has no previous backups
- }
- string sGroup;
- if (0 == stats.MessagesThisFile )
- {
- // first file has special pattern...since rolling
doesn't occur when message
- // is logged, rather before next message is logged.
- if (stats.NumberOfFileRolls <= 1 )
- {
- return null;
- }
- // Use backup files from previous round. The minus 2
is because we have already
- // rolled, and the first round uses null instead of the
string
- sGroup = GetBackupGroup( sBackupGroups,
stats.NumberOfFileRolls-2 );
- }
- else
- {
- sGroup = GetBackupGroup( sBackupGroups,
stats.NumberOfFileRolls-1 );
- }
- return MakeBackupFileEntriesFromBackupGroup( sGroup,
stats.MaximumFileSize );
- }
+ ///// <summary>
+ ///// Builds a collection of file entries based on the
file names
+ ///// specified in a groups string and the max file size
from the
+ ///// stats object
+ ///// </summary>
+ ///// <param
name="sBackupGroups"></param>
+ ///// <param name="stats"></param>
+ ///// <returns></returns>
+ //private RollFileEntry[]
MakeBackupFileEntriesForPreCondition( string sBackupGroups,
RollingStats stats )
+ //{
+ // if (0 == stats.NumberOfFileRolls )
+ // {
+ // return null; // first round has no previous
backups
+ // }
+ // string sGroup;
+ // if (0 == stats.MessagesThisFile )
+ // {
+ // // first file has special pattern...since
rolling doesn't occur when message
+ // // is logged, rather before next message is
logged.
+ // if (stats.NumberOfFileRolls <= 1 )
+ // {
+ // return null;
+ // }
+ // // Use backup files from previous round. The
minus 2 is because we have already
+ // // rolled, and the first round uses null
instead of the string
+ // sGroup = GetBackupGroup( sBackupGroups,
stats.NumberOfFileRolls-2 );
+ // }
+ // else
+ // {
+ // sGroup = GetBackupGroup( sBackupGroups,
stats.NumberOfFileRolls-1 );
+ // }
+ // return MakeBackupFileEntriesFromBackupGroup(
sGroup, stats.MaximumFileSize );
+ //}
/// <summary>
/// Builds a collection of file entries based on the file
names
 -601,14
+623,14 
/// <param
name="sBackupGroups"></param>
/// <param name="stats"></param>
/// <returns></returns>
- private RollFileEntry[]
MakeBackupFileEntriesForPostCondition( string sBackupGroups,
RollingStats stats )
+ private static RollFileEntry[]
MakeBackupFileEntriesForPostCondition(string sBackupGroups,
RollingStats stats)
{
if (0 == stats.NumberOfFileRolls)
{
- return null; // first round has no previous backups
+ return null; // first round has no previous backups
}
- string sGroup = GetBackupGroup( sBackupGroups,
stats.NumberOfFileRolls-1 );
- return MakeBackupFileEntriesFromBackupGroup( sGroup,
stats.MaximumFileSize );
+ string sGroup = GetBackupGroup(sBackupGroups,
stats.NumberOfFileRolls - 1);
+ return MakeBackupFileEntriesFromBackupGroup(sGroup,
stats.MaximumFileSize);
}
 -624,11
+646,6 
private int iNumberOfFileRolls;
/// <summary>
- /// Default constructor
- /// </summary>
- public RollingStats() {}
-
- /// <summary>
/// Number of total bytes a log file can reach.
/// </summary>
public int MaximumFileSize
 -644,7
+661,7 
public int TotalMessageLength
{
get { return iTotalMessageLength; }
- set { iTotalMessageLength = value;}
+ set { iTotalMessageLength = value; }
}
/// <summary>
 -682,14
+699,14 
/// </summary>
/// <param
name="sTestMessage"></param>
/// <returns></returns>
- private RollingStats InitializeStats( string sTestMessage
)
+ private static RollingStats InitializeStats(string
sTestMessage)
{
RollingStats rollingStats = new RollingStats();
- rollingStats.TotalMessageLength = TotalMessageLength(
sTestMessage );
- rollingStats.MessagesPerFile = MessagesPerFile(
rollingStats.TotalMessageLength );
- rollingStats.MessagesThisFile = 0;
- rollingStats.NumberOfFileRolls = 0;
+ rollingStats.TotalMessageLength =
TotalMessageLength(sTestMessage);
+ rollingStats.MessagesPerFile =
MessagesPerFile(rollingStats.TotalMessageLength);
+ rollingStats.MessagesThisFile = 0;
+ rollingStats.NumberOfFileRolls = 0;
return rollingStats;
}
 -703,19
+720,19 
/// <param
name="existing"></param>
/// <param name="final"></param>
/// <returns></returns>
- private RollFileEntry[] AddFinalElement( RollFileEntry[]
existing, RollFileEntry final )
+ private static RollFileEntry[]
AddFinalElement(RollFileEntry[] existing, RollFileEntry
final)
{
int iLength = 1;
- if (null != existing )
+ if (null != existing)
{
iLength += existing.Length;
}
RollFileEntry[] combined = new RollFileEntry[iLength];
- if (null != existing )
+ if (null != existing)
{
- System.Array.Copy( existing, 0, combined, 0,
existing.Length );
+ Array.Copy(existing, 0, combined, 0, existing.Length);
}
- combined[iLength-1] = final;
+ combined[iLength - 1] = final;
return combined;
}
 -729,15
+746,15 
/// <param
name="currentNext"></param>
/// <param
name="rollingStats"></param>
/// <returns></returns>
- private RollConditions BuildTableEntry( string
sBackupFiles, RollConditions preCondition, RollFileEntry
current, RollFileEntry currentNext, RollingStats
rollingStats )
+ private static RollConditions BuildTableEntry(string
sBackupFiles, RollConditions preCondition, RollFileEntry
current, RollFileEntry currentNext, RollingStats
rollingStats)
{
- RollFileEntry[] backupsPost =
MakeBackupFileEntriesForPostCondition( sBackupFiles,
rollingStats );
- RollFileEntry[] post = AddFinalElement( backupsPost,
currentNext );
- if (null == preCondition )
+ RollFileEntry[] backupsPost =
MakeBackupFileEntriesForPostCondition(sBackupFiles,
rollingStats);
+ RollFileEntry[] post = AddFinalElement(backupsPost,
currentNext);
+ if (null == preCondition)
{
- return new RollConditions( AddFinalElement(null,
current), post );
+ return new RollConditions(AddFinalElement(null,
current), post);
}
- return new RollConditions(
preCondition.GetPostLogFileEntries(), post );
+ return new
RollConditions(preCondition.GetPostLogFileEntries(), post);
}
/// <summary>
 -749,15
+766,15 
/// <param
name="rollingStats"></param>
/// <param
name="currentNext"></param>
/// <returns></returns>
- private RollFileEntry MoveNextEntry( RollingStats
rollingStats, RollFileEntry currentNext )
+ private static RollFileEntry MoveNextEntry(RollingStats
rollingStats, RollFileEntry currentNext)
{
rollingStats.MessagesThisFile =
rollingStats.MessagesThisFile + 1;
- if (rollingStats.MessagesThisFile >=
rollingStats.MessagesPerFile )
+ if (rollingStats.MessagesThisFile >=
rollingStats.MessagesPerFile)
{
rollingStats.MessagesThisFile = 0;
rollingStats.NumberOfFileRolls =
rollingStats.NumberOfFileRolls + 1;
- return new RollFileEntry( GetCurrentFile(), 0 );
+ return new RollFileEntry(GetCurrentFile(), 0);
}
else
{
 -771,10
+788,10 
/// </summary>
/// <param name="match"></param>
/// <returns></returns>
- private string NumberedNameMaker( Match match )
+ private static string NumberedNameMaker(Match match)
{
Int32 iValue = Int32.Parse(match.Value);
- return MakeFileName( _fileName, iValue );
+ return MakeFileName(c_fileName, iValue);
}
/// <summary>
 -785,10
+802,10 
/// <param
name="sBackupInfo"></param>
/// <param
name="evaluator"></param>
/// <returns></returns>
- string ConvertToFiles( string sBackupInfo, MatchEvaluator
evaluator )
+ private static string ConvertToFiles(string sBackupInfo,
MatchEvaluator evaluator)
{
Regex regex = new Regex( "d+");
- return regex.Replace( sBackupInfo, evaluator );
+ return regex.Replace(sBackupInfo, evaluator);
}
/// <summary>
 -799,13
+816,13 
/// that results after each message is
logged</param>
/// <param name="iMessagesToLog">How many
times the test message will be repeatedly
logged</param>
/// <returns></returns>
- private RollConditions[] MakeNumericTestEntries( string
sTestMessage, string sBackupInfo, int iMessagesToLog )
+ private static RollConditions[]
MakeNumericTestEntries(string sTestMessage, string
sBackupInfo, int iMessagesToLog)
{
- return MakeTestEntries(
- sTestMessage,
- sBackupInfo,
- iMessagesToLog,
- new MatchEvaluator(NumberedNameMaker ) );
+ return MakeTestEntries(
+ sTestMessage,
+ sBackupInfo,
+ iMessagesToLog,
+ new MatchEvaluator(NumberedNameMaker));
}
/// <summary>
 -820,31
+837,31 
/// <param name="iMessagesToLog">How many
times the test message will be repeatedly
logged</param>
/// <param name="evaluator">Function that
can turn a number into a filename</param>
/// <returns></returns>
- private RollConditions[] MakeTestEntries( string
sTestMessage, string sBackupInfo, int iMessagesToLog,
MatchEvaluator evaluator )
+ private static RollConditions[] MakeTestEntries(string
sTestMessage, string sBackupInfo, int iMessagesToLog,
MatchEvaluator evaluator)
{
- string sBackupFiles = ConvertToFiles( sBackupInfo,
evaluator );
+ string sBackupFiles = ConvertToFiles(sBackupInfo,
evaluator);
RollConditions[] table = new
RollConditions[iMessagesToLog];
- RollingStats rollingStats = InitializeStats(
sTestMessage );
+ RollingStats rollingStats =
InitializeStats(sTestMessage);
RollConditions preCondition = null;
rollingStats.MessagesThisFile = 0;
- RollFileEntry currentFile = new RollFileEntry(
GetCurrentFile(), 0 );
- for( int i=0; i<iMessagesToLog; i++ )
+ RollFileEntry currentFile = new
RollFileEntry(GetCurrentFile(), 0);
+ for(int i = 0; i < iMessagesToLog; i++)
{
- RollFileEntry currentNext = new RollFileEntry(
- GetCurrentFile(),
- (1 + rollingStats.MessagesThisFile) *
rollingStats.TotalMessageLength );
+ RollFileEntry currentNext = new RollFileEntry(
+ GetCurrentFile(),
+ (1 + rollingStats.MessagesThisFile) *
rollingStats.TotalMessageLength);
- table[i] = BuildTableEntry( sBackupFiles, preCondition,
currentFile, currentNext, rollingStats );
+ table[i] = BuildTableEntry(sBackupFiles, preCondition,
currentFile, currentNext, rollingStats);
preCondition = table[i];
//System.Diagnostics.Debug.WriteLine( "Message
" + i );
//DumpTableEntry( table[i] );
- currentFile = MoveNextEntry( rollingStats, currentNext
);
+ currentFile = MoveNextEntry(rollingStats,
currentNext);
}
return table;
 -871,10
+888,10 
/// occurs
/// </summary>
/// <param name="table"></param>
- private void VerifyRolling( RollConditions[] table )
+ private void VerifyRolling(RollConditions[] table)
{
ConfigureRootAppender();
- RollFromTableEntries( _fileName, table, _testMessage );
+ RollFromTableEntries(c_fileName, table, c_testMessage);
}
/// <summary>
 -883,7
+900,8 
/// Newest = N, Oldest = N-K, where K is the number of
backups to allow
/// and N is the number of times rolling has occurred.
/// </summary>
- [Test] public void TestRollingCountUpFixedBackups()
+ [Test]
+ public void TestRollingCountUpFixedBackups()
{
//
// Oldest to newest when reading in a group
left-to-right, so 1 2 3 means 1 is the
 -900,9
+918,9 
// Log 30 messages. This is 5 groups, 6 checks per
group ( 0, 100, 200, 300, 400, 500
// bytes for current file as messages are logged.
//
- int iMessagesToLog = 30;
+ int iMessagesToLog = 30;
- VerifyRolling( MakeNumericTestEntries( _testMessage,
sBackupInfo, iMessagesToLog ) );
+ VerifyRolling(MakeNumericTestEntries(c_testMessage,
sBackupInfo, iMessagesToLog));
}
/// <summary>
 -911,7
+929,8 
/// Newest = N, Oldest = 1, where N is the number of
times rolling has
/// occurred.
/// </summary>
- [Test] public void TestRollingCountUpInfiniteBackups()
+ [Test]
+ public void TestRollingCountUpInfiniteBackups()
{
//
// Oldest to newest when reading in a group
left-to-right, so 1 2 3 means 1 is the
 -933,9
+952,9 
// Log 30 messages. This is 5 groups, 6 checks per
group ( 0, 100, 200, 300, 400, 500
// bytes for current file as messages are logged.
//
- int iMessagesToLog = 30;
+ int iMessagesToLog = 30;
- VerifyRolling( MakeNumericTestEntries( _testMessage,
sBackupInfo, iMessagesToLog ) );
+ VerifyRolling(MakeNumericTestEntries(c_testMessage,
sBackupInfo, iMessagesToLog));
}
/// <summary>
 -943,7
+962,8 
/// Only the current file should be present, wrapping to
0 bytes once the
/// previous file fills up.
/// </summary>
- [Test] public void TestRollingCountUpZeroBackups()
+ [Test]
+ public void TestRollingCountUpZeroBackups()
{
//
// Oldest to newest when reading in a group
left-to-right, so 1 2 3 means 1 is the
 -965,9
+985,9 
// Log 30 messages. This is 5 groups, 6 checks per
group ( 0, 100, 200, 300, 400, 500
// bytes for current file as messages are logged.
//
- int iMessagesToLog = 30;
+ int iMessagesToLog = 30;
- VerifyRolling( MakeNumericTestEntries( _testMessage,
sBackupInfo, iMessagesToLog ) );
+ VerifyRolling(MakeNumericTestEntries(c_testMessage,
sBackupInfo, iMessagesToLog));
}
 -976,7
+996,8 
/// count direction set to down, so that older files have
higher counts.
/// Newest = 1, Oldest = N, where N is the number of
backups to allow
/// </summary>
- [Test] public void TestRollingCountDownFixedBackups()
+ [Test]
+ public void TestRollingCountDownFixedBackups()
{
//
// Oldest to newest when reading in a group
left-to-right, so 1 2 3 means 1 is the
 -993,9
+1014,9 
// Log 30 messages. This is 5 groups, 6 checks per
group ( 0, 100, 200, 300, 400, 500
// bytes for current file as messages are logged.
//
- int iMessagesToLog = 30;
+ int iMessagesToLog = 30;
- VerifyRolling( MakeNumericTestEntries( _testMessage,
sBackupInfo, iMessagesToLog ) );
+ VerifyRolling(MakeNumericTestEntries(c_testMessage,
sBackupInfo, iMessagesToLog));
}
/// <summary>
 -1004,7
+1025,8 
/// Newest = 1, Oldest = N, where N is the number of
times rolling has
/// occurred
/// </summary>
- [Test] public void TestRollingCountDownInfiniteBackups()
+ [Test]
+ public void TestRollingCountDownInfiniteBackups()
{
//
// Oldest to newest when reading in a group
left-to-right, so 1 2 3 means 1 is the
 -1026,9
+1048,9 
// Log 30 messages. This is 5 groups, 6 checks per
group ( 0, 100, 200, 300, 400, 500
// bytes for current file as messages are logged.
//
- int iMessagesToLog = 30;
+ int iMessagesToLog = 30;
- VerifyRolling( MakeNumericTestEntries( _testMessage,
sBackupInfo, iMessagesToLog ) );
+ VerifyRolling(MakeNumericTestEntries(c_testMessage,
sBackupInfo, iMessagesToLog));
}
/// <summary>
 -1036,7
+1058,8 
/// Only the current file should be present, wrapping to
0 bytes once the
/// previous file fills up.
/// </summary>
- [Test] public void TestRollingCountDownZeroBackups()
+ [Test]
+ public void TestRollingCountDownZeroBackups()
{
//
// Oldest to newest when reading in a group
left-to-right, so 1 2 3 means 1 is the
 -1058,9
+1081,9 
// Log 30 messages. This is 5 groups, 6 checks per
group ( 0, 100, 200, 300, 400, 500
// bytes for current file as messages are logged.
//
- int iMessagesToLog = 30;
+ int iMessagesToLog = 30;
- VerifyRolling( MakeNumericTestEntries( _testMessage,
sBackupInfo, iMessagesToLog ) );
+ VerifyRolling(MakeNumericTestEntries(c_testMessage,
sBackupInfo, iMessagesToLog));
}
/// <summary>
 -1068,16
+1091,16 
/// </summary>
private void ConfigureRootAppender()
{
- _root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepos
itory()).Root;
+ _root =
((Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
.Root;
_root.Level = Level.Debug;
_caRoot = new CountingAppender();
_root.AddAppender(_caRoot);
- Assert.AreEqual(_caRoot.Counter, 0);
+ Assert.AreEqual(_caRoot.Counter, 0);
//
// Set the root appender with a RollingFileAppender
//
- _root.AddAppender( CreateAppender() );
+ _root.AddAppender(CreateAppender());
_root.Repository.Configured = true;
}

-1088,151 +1111,163 
/// <param
name="sBaseFile"></param>
/// <param name="alFiles"></param>
/// <param
name="iExpectedCurSizeRollBackups"></param&g
t;
- private void VerifyInitializeRollBackupsFromBaseFile(
string sBaseFile, ArrayList alFiles, int
iExpectedCurSizeRollBackups )
+ private static void
VerifyInitializeRollBackupsFromBaseFile(string sBaseFile,
ArrayList alFiles, int iExpectedCurSizeRollBackups)
{
- InitializeAndVerifyExpectedValue( alFiles, sBaseFile,
CreateRollingFileAppender( "5,0,1" ),
iExpectedCurSizeRollBackups );
+ InitializeAndVerifyExpectedValue(alFiles, sBaseFile,
CreateRollingFileAppender("5,0,1"),
iExpectedCurSizeRollBackups);
}
/// <summary>
/// Tests that the current backup index is 0 when no
/// existing files are seen
/// </summary>
- [Test] public void TestInitializeRollBackups1()
+ [Test]
+ public void TestInitializeRollBackups1()
{
string sBaseFile = "LogFile.log";
ArrayList arrFiles = new ArrayList();
- arrFiles.Add( "junk1" );
- arrFiles.Add( "junk1.log" );
- arrFiles.Add( "junk2.log" );
- arrFiles.Add( "junk.log.1" );
- arrFiles.Add( "junk.log.2" );
+ arrFiles.Add("junk1");
+ arrFiles.Add("junk1.log");
+ arrFiles.Add("junk2.log");
+ arrFiles.Add("junk.log.1");
+ arrFiles.Add("junk.log.2");
int iExpectedCurSizeRollBackups = 0;
- VerifyInitializeRollBackupsFromBaseFile( sBaseFile,
arrFiles, iExpectedCurSizeRollBackups );
+ VerifyInitializeRollBackupsFromBaseFile(sBaseFile,
arrFiles, iExpectedCurSizeRollBackups);
}
/// <summary>
/// Verifies that files are detected when the base file
is specified
/// </summary>
/// <param
name="sBaseFile"></param>
- private void VerifyInitializeRollBackupsFromBaseFile(
string sBaseFile )
+ private static void
VerifyInitializeRollBackupsFromBaseFile(string sBaseFile)
{
- ArrayList alFiles = MakeTestDataFromString( sBaseFile,
"0,1,2" );
+ ArrayList alFiles = MakeTestDataFromString(sBaseFile,
"0,1,2");
int iExpectedCurSizeRollBackups = 2;
- VerifyInitializeRollBackupsFromBaseFile( sBaseFile,
alFiles, iExpectedCurSizeRollBackups );
+ VerifyInitializeRollBackupsFromBaseFile(sBaseFile,
alFiles, iExpectedCurSizeRollBackups);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountUpFixed()
+ [Test]
+ public void TestInitializeCountUpFixed()
{
- ArrayList alFiles = MakeTestDataFromString(
"3,4,5" );
+ ArrayList alFiles =
MakeTestDataFromString("3,4,5");
int iExpectedValue = 5;
- InitializeAndVerifyExpectedValue( alFiles, _fileName,
CreateRollingFileAppender( "3,0,1" ),
iExpectedValue );
+ InitializeAndVerifyExpectedValue(alFiles, c_fileName,
CreateRollingFileAppender("3,0,1"),
iExpectedValue);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountUpFixed2()
+ [Test]
+ public void TestInitializeCountUpFixed2()
{
- ArrayList alFiles = MakeTestDataFromString(
"0,3" );
+ ArrayList alFiles =
MakeTestDataFromString("0,3");
int iExpectedValue = 3;
- InitializeAndVerifyExpectedValue( alFiles, _fileName,
CreateRollingFileAppender( "3,0,1" ),
iExpectedValue );
+ InitializeAndVerifyExpectedValue(alFiles, c_fileName,
CreateRollingFileAppender("3,0,1"),
iExpectedValue);
}
/// <summary>
/// Verifies that count stays at 0 for the zero backups
case
/// when counting up
/// </summary>
- [Test] public void TestInitializeCountUpZeroBackups()
+ [Test]
+ public void TestInitializeCountUpZeroBackups()
{
- ArrayList alFiles = MakeTestDataFromString(
"0,3" );
+ ArrayList alFiles =
MakeTestDataFromString("0,3");
int iExpectedValue = 0;
- InitializeAndVerifyExpectedValue( alFiles, _fileName,
CreateRollingFileAppender( "0,0,1" ),
iExpectedValue );
+ InitializeAndVerifyExpectedValue(alFiles, c_fileName,
CreateRollingFileAppender("0,0,1"),
iExpectedValue);
}
/// <summary>
/// Verifies that count stays at 0 for the zero backups
case
/// when counting down
/// </summary>
- [Test] public void TestInitializeCountDownZeroBackups()
+ [Test]
+ public void TestInitializeCountDownZeroBackups()
{
- ArrayList alFiles = MakeTestDataFromString(
"0,3" );
+ ArrayList alFiles =
MakeTestDataFromString("0,3");
int iExpectedValue = 0;
- InitializeAndVerifyExpectedValue( alFiles, _fileName,
CreateRollingFileAppender( "0,0,-1" ),
iExpectedValue );
+ InitializeAndVerifyExpectedValue(alFiles, c_fileName,
CreateRollingFileAppender("0,0,-1"),
iExpectedValue);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountDownFixed()
+ [Test]
+ public void TestInitializeCountDownFixed()
{
- ArrayList alFiles = MakeTestDataFromString(
"4,5,6" );
- VerifyInitializeDownFixedExpectedValue( alFiles,
_fileName, 0 );
+ ArrayList alFiles =
MakeTestDataFromString("4,5,6");
+ VerifyInitializeDownFixedExpectedValue(alFiles,
c_fileName, 0);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountDownFixed2()
+ [Test]
+ public void TestInitializeCountDownFixed2()
{
- ArrayList alFiles = MakeTestDataFromString(
"1,5,6" );
- VerifyInitializeDownFixedExpectedValue( alFiles,
_fileName, 1 );
+ ArrayList alFiles =
MakeTestDataFromString("1,5,6");
+ VerifyInitializeDownFixedExpectedValue(alFiles,
c_fileName, 1);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountDownFixed3()
+ [Test]
+ public void TestInitializeCountDownFixed3()
{
- ArrayList alFiles = MakeTestDataFromString(
"2,5,6" );
- VerifyInitializeDownFixedExpectedValue( alFiles,
_fileName, 2 );
+ ArrayList alFiles =
MakeTestDataFromString("2,5,6");
+ VerifyInitializeDownFixedExpectedValue(alFiles,
c_fileName, 2);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountDownFixed4()
+ [Test]
+ public void TestInitializeCountDownFixed4()
{
- ArrayList alFiles = MakeTestDataFromString(
"3,5,6" );
- VerifyInitializeDownFixedExpectedValue( alFiles,
_fileName, 3 );
+ ArrayList alFiles =
MakeTestDataFromString("3,5,6");
+ VerifyInitializeDownFixedExpectedValue(alFiles,
c_fileName, 3);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountDownFixed5()
+ [Test]
+ public void TestInitializeCountDownFixed5()
{
- ArrayList alFiles = MakeTestDataFromString(
"1,2,3" );
- VerifyInitializeDownFixedExpectedValue( alFiles,
_fileName, 3 );
+ ArrayList alFiles =
MakeTestDataFromString("1,2,3");
+ VerifyInitializeDownFixedExpectedValue(alFiles,
c_fileName, 3);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountDownFixed6()
+ [Test]
+ public void TestInitializeCountDownFixed6()
{
- ArrayList alFiles = MakeTestDataFromString(
"1,2" );
- VerifyInitializeDownFixedExpectedValue( alFiles,
_fileName, 2 );
+ ArrayList alFiles =
MakeTestDataFromString("1,2");
+ VerifyInitializeDownFixedExpectedValue(alFiles,
c_fileName, 2);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// </summary>
- [Test] public void TestInitializeCountDownFixed7()
+ [Test]
+ public void TestInitializeCountDownFixed7()
{
- ArrayList alFiles = MakeTestDataFromString(
"2,3" );
- VerifyInitializeDownFixedExpectedValue( alFiles,
_fileName, 3 );
+ ArrayList alFiles =
MakeTestDataFromString("2,3");
+ VerifyInitializeDownFixedExpectedValue(alFiles,
c_fileName, 3);
}
- private void InitializeAndVerifyExpectedValue( ArrayList
alFiles, string sBaseFile, RollingFileAppender rfa, int
iExpectedValue )
+ private static void
InitializeAndVerifyExpectedValue(ArrayList alFiles, string
sBaseFile, RollingFileAppender rfa, int iExpectedValue)
{
- InitializeRollBackups( rfa, sBaseFile, alFiles );
- Assert.AreEqual( iExpectedValue,
GetFieldCurSizeRollBackups(rfa) );
+ InitializeRollBackups(rfa, sBaseFile, alFiles);
+ Assert.AreEqual(iExpectedValue,
GetFieldCurSizeRollBackups(rfa));
}
/// <summary>
 -1242,9
+1277,9 
/// <param name="alFiles"></param>
/// <param
name="sBaseFile"></param>
/// <param
name="iExpectedValue"></param>
- private void VerifyInitializeDownInfiniteExpectedValue(
ArrayList alFiles, string sBaseFile, int iExpectedValue )
+ private static void
VerifyInitializeDownInfiniteExpectedValue(ArrayList alFiles,
string sBaseFile, int iExpectedValue)
{
- InitializeAndVerifyExpectedValue( alFiles, sBaseFile,
CreateRollingFileAppender( "-1,0,-1" ),
iExpectedValue );
+ InitializeAndVerifyExpectedValue(alFiles, sBaseFile,
CreateRollingFileAppender("-1,0,-1"),
iExpectedValue);
}
/// <summary>
 -1254,19
+1289,19 
/// </summary>
/// <param name="sParams"></param>
/// <returns></returns>
- private RollingFileAppender CreateRollingFileAppender(
string sParams )
+ private static RollingFileAppender
CreateRollingFileAppender(string sParams)
{
string[] asParams = sParams.Split(',');
- if (null == asParams || asParams.Length != 3 )
+ if (null == asParams || asParams.Length != 3)
{
- throw new ArgumentOutOfRangeException(sParams, sParams,
"Must have 3 comma separated params:
MaxSizeRollBackups, CurSizeRollBackups, CountDirection"
);
+ throw new ArgumentOutOfRangeException(sParams, sParams,
"Must have 3 comma separated params:
MaxSizeRollBackups, CurSizeRollBackups,
CountDirection");
}
RollingFileAppender rfa = new RollingFileAppender();
rfa.RollingStyle =
RollingFileAppender.RollingMode.Size;
SetFieldMaxSizeRollBackups(rfa,
Int32.Parse(asParams[0].Trim()));
SetFieldCurSizeRollBackups(rfa,
Int32.Parse(asParams[1].Trim()));
- rfa.CountDirection =
Int32.Parse(asParams[2].Trim());
+ rfa.CountDirection = Int32.Parse(asParams[2].Trim());
return rfa;
}
 -1275,60
+1310,66 
/// Verifies that count goes to the highest when counting
down
/// and infinite backups are selected
/// </summary>
- [Test] public void TestInitializeCountDownInfinite()
+ [Test]
+ public void TestInitializeCountDownInfinite()
{
- ArrayList alFiles = MakeTestDataFromString(
"2,3" );
- VerifyInitializeDownInfiniteExpectedValue( alFiles,
_fileName, 3 );
+ ArrayList alFiles =
MakeTestDataFromString("2,3");
+ VerifyInitializeDownInfiniteExpectedValue(alFiles,
c_fileName, 3);
}
/// <summary>
/// Verifies that count goes to the highest when counting
down
/// and infinite backups are selected
/// </summary>
- [Test] public void TestInitializeCountDownInfinite2()
+ [Test]
+ public void TestInitializeCountDownInfinite2()
{
- ArrayList alFiles = MakeTestDataFromString(
"2,3,4,5,6,7,8,9,10" );
- VerifyInitializeDownInfiniteExpectedValue( alFiles,
_fileName, 10 );
+ ArrayList alFiles =
MakeTestDataFromString("2,3,4,5,6,7,8,9,10");
+ VerifyInitializeDownInfiniteExpectedValue(alFiles,
c_fileName, 10);
}
/// <summary>
/// Verifies that count goes to the highest when counting
down
/// and infinite backups are selected
/// </summary>
- [Test] public void TestInitializeCountDownInfinite3()
+ [Test]
+ public void TestInitializeCountDownInfinite3()
{
- ArrayList alFiles = MakeTestDataFromString(
"9,10,3,4,5,7,9,6,1,2,8" );
- VerifyInitializeDownInfiniteExpectedValue( alFiles,
_fileName, 10 );
+ ArrayList alFiles =
MakeTestDataFromString("9,10,3,4,5,7,9,6,1,2,8");
+ VerifyInitializeDownInfiniteExpectedValue(alFiles,
c_fileName, 10);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// and infinite backups are selected
/// </summary>
- [Test] public void TestInitializeCountUpInfinite()
+ [Test]
+ public void TestInitializeCountUpInfinite()
{
- ArrayList alFiles = MakeTestDataFromString(
"2,3" );
- VerifyInitializeUpInfiniteExpectedValue( alFiles,
_fileName, 3 );
+ ArrayList alFiles =
MakeTestDataFromString("2,3");
+ VerifyInitializeUpInfiniteExpectedValue(alFiles,
c_fileName, 3);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// and infinite backups are selected
/// </summary>
- [Test] public void TestInitializeCountUpInfinite2()
+ [Test]
+ public void TestInitializeCountUpInfinite2()
{
- ArrayList alFiles = MakeTestDataFromString(
"2,3,4,5,6,7,8,9,10" );
- VerifyInitializeUpInfiniteExpectedValue( alFiles,
_fileName, 10 );
+ ArrayList alFiles =
MakeTestDataFromString("2,3,4,5,6,7,8,9,10");
+ VerifyInitializeUpInfiniteExpectedValue(alFiles,
c_fileName, 10);
}
/// <summary>
/// Verifies that count goes to the highest when counting
up
/// and infinite backups are selected
/// </summary>
- [Test] public void TestInitializeCountUpInfinite3()
+ [Test]
+ public void TestInitializeCountUpInfinite3()
{
- ArrayList alFiles = MakeTestDataFromString(
"9,10,3,4,5,7,9,6,1,2,8" );
- VerifyInitializeUpInfiniteExpectedValue( alFiles,
_fileName, 10 );
+ ArrayList alFiles =
MakeTestDataFromString("9,10,3,4,5,7,9,6,1,2,8");
+ VerifyInitializeUpInfiniteExpectedValue(alFiles,
c_fileName, 10);
}
/// <summary>
 -1338,21
+1379,24 
/// <param name="lockModel">The locking
model to use.</param>
/// <param name="handler">The error
handler to use.</param>
/// <returns>A configured ILogger</returns>
- private ILogger CreateLogger(string
filename,FileAppender.LockingModelBase lockModel,
IErrorHandler handler)
+ private static ILogger CreateLogger(string filename,
FileAppender.LockingModelBase lockModel, IErrorHandler
handler)
{
- log4net.Repository.Hierarchy.Hierarchy h =
(log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.C
reateRepository("TestRepository");
+ Repository.Hierarchy.Hierarchy h =
(Repository.Hierarchy.Hierarchy)LogManager.CreateRepository(
"TestRepository");
- log4net.Appender.RollingFileAppender appender = new
log4net.Appender.RollingFileAppender();
+ RollingFileAppender appender = new
RollingFileAppender();
appender.File = filename;
appender.AppendToFile = false;
- appender.CountDirection=0;
- appender.RollingStyle=RollingFileAppender.RollingMode.Si
ze;
- appender.MaxFileSize=100000;
- appender.Encoding=System.Text.Encoding.ASCII;
- appender.ErrorHandler=handler;
- if (lockModel!=null) {appender.LockingModel=lockModel;}
-
- log4net.Layout.PatternLayout layout = new
log4net.Layout.PatternLayout();
+ appender.CountDirection = 0;
+ appender.RollingStyle =
RollingFileAppender.RollingMode.Size;
+ appender.MaxFileSize = 100000;
+ appender.Encoding = Encoding.ASCII;
+ appender.ErrorHandler = handler;
+ if (lockModel != null)
+ {
+ appender.LockingModel = lockModel;
+ }
+
+ PatternLayout layout = new PatternLayout();
layout.ConversionPattern = "%m%n";
layout.ActivateOptions();

-1362,208 +1406,220 
h.Root.AddAppender(appender);
h.Configured = true;
- ILogger log=h.GetLogger("Logger");
+ ILogger log = h.GetLogger("Logger");
return log;
}
/// <summary>
- /// Destroys the logger hierarchy created by <see
cref="RollingFileAppenderTests.CreateLogger"/>
+ /// Destroys the logger hierarchy created by <see
cref="RollingFileAppenderTest.CreateLogger"/>
/// </summary>
- private void DestroyLogger()
+ private static void DestroyLogger()
{
- log4net.Repository.Hierarchy.Hierarchy h =
(log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.G
etRepository("TestRepository");
+ Repository.Hierarchy.Hierarchy h =
(Repository.Hierarchy.Hierarchy)LogManager.GetRepository(&qu
ot;TestRepository");
h.ResetConfiguration();
//Replace the repository selector so that we can
recreate the hierarchy with the same name if necessary
- LoggerManager.RepositorySelector=new
DefaultRepositorySelector(log4net.Util.SystemInfo.GetTypeFro
mString("log4net.Repository.Hierarchy.Hierarchy",t
rue,true));
+ LoggerManager.RepositorySelector = new
DefaultRepositorySelector(SystemInfo.GetTypeFromString("
;log4net.Repository.Hierarchy.Hierarchy", true,
true));
}
- private void AssertFileEquals(string filename, string
contents)
+ private static void AssertFileEquals(string filename,
string contents)
{
- StreamReader sr=new StreamReader(filename);
- string logcont=sr.ReadToEnd();
+ StreamReader sr = new StreamReader(filename);
+ string logcont = sr.ReadToEnd();
sr.Close();
- Assert.AreEqual(contents,logcont, "Log contents is
not what is expected");
+ Assert.AreEqual(contents, logcont, "Log contents is
not what is expected");
- System.IO.File.Delete(filename);
+ File.Delete(filename);
}
/// <summary>
/// Verifies that logging a message actually produces
output
/// </summary>
- [Test] public void TestLogOutput()
+ [Test]
+ public void TestLogOutput()
{
- String filename="test.log";
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,new
FileAppender.ExclusiveLock(), sh);
- log.Log(this.GetType(),Level.Info,"This is a
message",null);
- log.Log(this.GetType(),Level.Info,"This is a
message 2",null);
+ String filename = "test.log";
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, new
FileAppender.ExclusiveLock(), sh);
+ log.Log(GetType(), Level.Info, "This is a
message", null);
+ log.Log(GetType(), Level.Info, "This is a message
2", null);
DestroyLogger();
- AssertFileEquals(filename,"This is a
message"+Environment.NewLine+"This is a message
2"+Environment.NewLine);
- Assert.AreEqual("",sh.Message,
"Unexpected error message");
+ AssertFileEquals(filename, "This is a message"
+ Environment.NewLine + "This is a message 2" +
Environment.NewLine);
+ Assert.AreEqual("", sh.Message,
"Unexpected error message");
}
/// <summary>
/// Verifies that attempting to log to a locked file
fails gracefully
/// </summary>
- [Test] public void TestExclusiveLockFails()
+ [Test]
+ public void TestExclusiveLockFails()
{
- String filename="test.log";
+ String filename = "test.log";
- FileStream fs=new
FileStream(filename,FileMode.Create,FileAccess.Write,FileSha
re.None);
- fs.Write(System.Text.Encoding.ASCII.GetBytes("Test&
quot;),0,4);
+ FileStream fs = new FileStream(filename,
FileMode.Create, FileAccess.Write, FileShare.None);
+ fs.Write(Encoding.ASCII.GetBytes("Test"), 0,
4);
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,new
FileAppender.ExclusiveLock(),sh);
- log.Log(this.GetType(),Level.Info,"This is a
message",null);
- log.Log(this.GetType(),Level.Info,"This is a
message 2",null);
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, new
FileAppender.ExclusiveLock(), sh);
+ log.Log(GetType(), Level.Info, "This is a
message", null);
+ log.Log(GetType(), Level.Info, "This is a message
2", null);
DestroyLogger();
fs.Close();
- AssertFileEquals(filename,"Test");
- Assert.AreEqual(sh.Message.Substring(0,30), "Unable
to acquire lock on file", "Expecting an error
message");
+ AssertFileEquals(filename, "Test");
+ Assert.AreEqual(sh.Message.Substring(0, 30),
"Unable to acquire lock on file", "Expecting
an error message");
}
/// <summary>
/// Verifies that attempting to log to a locked file
recovers if the lock is released
/// </summary>
- [Test] public void TestExclusiveLockRecovers()
+ [Test]
+ public void TestExclusiveLockRecovers()
{
- String filename="test.log";
+ String filename = "test.log";
- FileStream fs=new
FileStream(filename,FileMode.Create,FileAccess.Write,FileSha
re.None);
- fs.Write(System.Text.Encoding.ASCII.GetBytes("Test&
quot;),0,4);
+ FileStream fs = new FileStream(filename,
FileMode.Create, FileAccess.Write, FileShare.None);
+ fs.Write(Encoding.ASCII.GetBytes("Test"), 0,
4);
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,new
FileAppender.ExclusiveLock(),sh);
- log.Log(this.GetType(),Level.Info,"This is a
message",null);
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, new
FileAppender.ExclusiveLock(), sh);
+ log.Log(GetType(), Level.Info, "This is a
message", null);
fs.Close();
- log.Log(this.GetType(),Level.Info,"This is a
message 2",null);
+ log.Log(GetType(), Level.Info, "This is a message
2", null);
DestroyLogger();
- AssertFileEquals(filename,"This is a message
2"+Environment.NewLine);
- Assert.AreEqual("Unable to acquire lock on
file",sh.Message.Substring(0,30), "Expecting an
error message");
+ AssertFileEquals(filename, "This is a message
2" + Environment.NewLine);
+ Assert.AreEqual("Unable to acquire lock on
file", sh.Message.Substring(0, 30), "Expecting an
error message");
}
/// <summary>
/// Verifies that attempting to log to a file with
ExclusiveLock really locks the file
/// </summary>
- [Test] public void TestExclusiveLockLocks()
+ [Test]
+ public void TestExclusiveLockLocks()
{
- String filename="test.log";
- bool locked=false;
+ String filename = "test.log";
+ bool locked = false;
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,new
FileAppender.ExclusiveLock(),sh);
- log.Log(this.GetType(),Level.Info,"This is a
message",null);
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, new
FileAppender.ExclusiveLock(), sh);
+ log.Log(GetType(), Level.Info, "This is a
message", null);
try
{
- FileStream fs=new
FileStream(filename,FileMode.Create,FileAccess.Write,FileSha
re.None);
- fs.Write(System.Text.Encoding.ASCII.GetBytes("Test
"),0,4);
+ FileStream fs = new FileStream(filename,
FileMode.Create, FileAccess.Write, FileShare.None);
+ fs.Write(Encoding.ASCII.GetBytes("Test"), 0,
4);
fs.Close();
}
- catch (System.IO.IOException e1)
+ catch(IOException e1)
{
- Assert.AreEqual("The process cannot access the
file ",e1.Message.Substring(0,35), "Unexpected
exception");
- locked=true;
+#if MONO
+ Assert.AreEqual("Sharing violation on path ",
e1.Message.Substring(0, 26), "Unexpected
exception");
+#else
+ Assert.AreEqual("The process cannot access the
file ", e1.Message.Substring(0, 35), "Unexpected
exception");
+#endif
+ locked = true;
}
- log.Log(this.GetType(),Level.Info,"This is a
message 2",null);
+ log.Log(GetType(), Level.Info, "This is a message
2", null);
DestroyLogger();
Assert.IsTrue(locked, "File was not locked");
- AssertFileEquals(filename,"This is a
message"+Environment.NewLine+"This is a message
2"+Environment.NewLine);
- Assert.AreEqual("",sh.Message,
"Unexpected error message");
+ AssertFileEquals(filename, "This is a message"
+ Environment.NewLine + "This is a message 2" +
Environment.NewLine);
+ Assert.AreEqual("", sh.Message,
"Unexpected error message");
}
/// <summary>
/// Verifies that attempting to log to a locked file
fails gracefully
/// </summary>
- [Test] public void TestMinimalLockFails()
+ [Test]
+ public void TestMinimalLockFails()
{
- String filename="test.log";
+ String filename = "test.log";
- FileStream fs=new
FileStream(filename,FileMode.Create,FileAccess.Write,FileSha
re.None);
- fs.Write(System.Text.Encoding.ASCII.GetBytes("Test&
quot;),0,4);
+ FileStream fs = new FileStream(filename,
FileMode.Create, FileAccess.Write, FileShare.None);
+ fs.Write(Encoding.ASCII.GetBytes("Test"), 0,
4);
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,new
FileAppender.MinimalLock(),sh);
- log.Log(this.GetType(),Level.Info,"This is a
message",null);
- log.Log(this.GetType(),Level.Info,"This is a
message 2",null);
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, new
FileAppender.MinimalLock(), sh);
+ log.Log(GetType(), Level.Info, "This is a
message", null);
+ log.Log(GetType(), Level.Info, "This is a message
2", null);
DestroyLogger();
fs.Close();
- AssertFileEquals(filename,"Test");
- Assert.AreEqual("Unable to acquire lock on
file",sh.Message.Substring(0,30), "Expecting an
error message");
+ AssertFileEquals(filename, "Test");
+ Assert.AreEqual("Unable to acquire lock on
file", sh.Message.Substring(0, 30), "Expecting an
error message");
}
/// <summary>
/// Verifies that attempting to log to a locked file
recovers if the lock is released
/// </summary>
- [Test] public void TestMinimalLockRecovers()
+ [Test]
+ public void TestMinimalLockRecovers()
{
- String filename="test.log";
+ String filename = "test.log";
- FileStream fs=new
FileStream(filename,FileMode.Create,FileAccess.Write,FileSha
re.None);
- fs.Write(System.Text.Encoding.ASCII.GetBytes("Test&
quot;),0,4);
+ FileStream fs = new FileStream(filename,
FileMode.Create, FileAccess.Write, FileShare.None);
+ fs.Write(Encoding.ASCII.GetBytes("Test"), 0,
4);
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,new
FileAppender.MinimalLock(),sh);
- log.Log(this.GetType(),Level.Info,"This is a
message",null);
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, new
FileAppender.MinimalLock(), sh);
+ log.Log(GetType(), Level.Info, "This is a
message", null);
fs.Close();
- log.Log(this.GetType(),Level.Info,"This is a
message 2",null);
+ log.Log(GetType(), Level.Info, "This is a message
2", null);
DestroyLogger();
- AssertFileEquals(filename,"This is a message
2"+Environment.NewLine);
- Assert.AreEqual("Unable to acquire lock on
file",sh.Message.Substring(0,30), "Expecting an
error message");
+ AssertFileEquals(filename, "This is a message
2" + Environment.NewLine);
+ Assert.AreEqual("Unable to acquire lock on
file", sh.Message.Substring(0, 30), "Expecting an
error message");
}
/// <summary>
/// Verifies that attempting to log to a file with
ExclusiveLock really locks the file
/// </summary>
- [Test] public void TestMinimalLockUnlocks()
+ [Test]
+ public void TestMinimalLockUnlocks()
{
- String filename="test.log";
- bool locked=false;
+ String filename = "test.log";
+ bool locked;
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,new
FileAppender.MinimalLock(),sh);
- log.Log(this.GetType(),Level.Info,"This is a
message",null);
-
- locked=true;
- FileStream fs=new
FileStream(filename,FileMode.Append,FileAccess.Write,FileSha
re.None);
- fs.Write(System.Text.Encoding.ASCII.GetBytes("Test&
quot;+Environment.NewLine),0,4+Environment.NewLine.Length);
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, new
FileAppender.MinimalLock(), sh);
+ log.Log(GetType(), Level.Info, "This is a
message", null);
+
+ locked = true;
+ FileStream fs = new FileStream(filename,
FileMode.Append, FileAccess.Write, FileShare.None);
+ fs.Write(Encoding.ASCII.GetBytes("Test" +
Environment.NewLine), 0, 4 + Environment.NewLine.Length);
fs.Close();
- log.Log(this.GetType(),Level.Info,"This is a
message 2",null);
+ log.Log(GetType(), Level.Info, "This is a message
2", null);
DestroyLogger();
Assert.IsTrue(locked, "File was not locked");
- AssertFileEquals(filename,"This is a
message"+Environment.NewLine+"Test"+Environme
nt.NewLine+"This is a message
2"+Environment.NewLine);
- Assert.AreEqual("",sh.Message,
"Unexpected error message");
+ AssertFileEquals(filename, "This is a message"
+ Environment.NewLine + "Test" +
Environment.NewLine + "This is a message 2" +
Environment.NewLine);
+ Assert.AreEqual("", sh.Message,
"Unexpected error message");
}
/// <summary>
/// Verify that the default LockModel is ExclusiveLock,
to maintain backwards compatibility with previous behaviour
/// </summary>
- [Test] public void TestDefaultLockingModel()
+ [Test]
+ public void TestDefaultLockingModel()
{
- String filename="test.log";
- SilentErrorHandler sh=new SilentErrorHandler();
- ILogger log=CreateLogger(filename,null,sh);
+ String filename = "test.log";
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, null, sh);
- IAppender[] appenders=log.Repository.GetAppenders();
- Assert.AreEqual(1,appenders.Length, "The wrong
number of appenders are configured");
+ IAppender[] appenders = log.Repository.GetAppenders();
+ Assert.AreEqual(1, appenders.Length, "The wrong
number of appenders are configured");
- RollingFileAppender
rfa=(RollingFileAppender)(appenders[0]);
- Assert.AreEqual(log4net.Util.SystemInfo.GetTypeFromStrin
g("log4net.Appender.FileAppender+ExclusiveLock",tr
ue,true),rfa.LockingModel.GetType(), "The LockingModel
is of an unexpected type");
+ RollingFileAppender rfa =
(RollingFileAppender)(appenders[0]);
+ Assert.AreEqual(SystemInfo.GetTypeFromString("log4n
et.Appender.FileAppender+ExclusiveLock", true, true),
rfa.LockingModel.GetType(), "The LockingModel is of an
unexpected type");
DestroyLogger();
}
-
+
/// <summary>
/// Tests the count up case, with infinite max backups ,
to see that
/// initialization of the rolling file appender results
in the expected value
 -1571,13
+1627,12 
/// <param name="alFiles"></param>
/// <param
name="sBaseFile"></param>
/// <param
name="iExpectedValue"></param>
- private void VerifyInitializeUpInfiniteExpectedValue(
ArrayList alFiles, string sBaseFile, int iExpectedValue )
+ private static void
VerifyInitializeUpInfiniteExpectedValue(ArrayList alFiles,
string sBaseFile, int iExpectedValue)
{
- InitializeAndVerifyExpectedValue( alFiles, sBaseFile,
CreateRollingFileAppender( "-1,0,1" ),
iExpectedValue );
+ InitializeAndVerifyExpectedValue(alFiles, sBaseFile,
CreateRollingFileAppender("-1,0,1"),
iExpectedValue);
}
-
/// <summary>
/// Tests the count down case, with max backups limited
to 3, to see that
/// initialization of the rolling file appender results
in the expected value
 -1585,9
+1640,9 
/// <param name="alFiles"></param>
/// <param
name="sBaseFile"></param>
/// <param
name="iExpectedValue"></param>
- private void VerifyInitializeDownFixedExpectedValue(
ArrayList alFiles, string sBaseFile, int iExpectedValue )
+ private static void
VerifyInitializeDownFixedExpectedValue(ArrayList alFiles,
string sBaseFile, int iExpectedValue)
{
- InitializeAndVerifyExpectedValue( alFiles, sBaseFile,
CreateRollingFileAppender( "3,0,-1" ),
iExpectedValue );
+ InitializeAndVerifyExpectedValue(alFiles, sBaseFile,
CreateRollingFileAppender("3,0,-1"),
iExpectedValue);
}
/// <summary>
 -1599,9
+1654,9 
/// </summary>
/// <param name="sFileNumbers">Comma
separated list of numbers for counted file
names</param>
/// <returns></returns>
- private ArrayList MakeTestDataFromString( string
sFileNumbers )
+ private static ArrayList MakeTestDataFromString(string
sFileNumbers)
{
- return MakeTestDataFromString( _fileName, sFileNumbers
);
+ return MakeTestDataFromString(c_fileName,
sFileNumbers);
}
/// <summary>
 -1613,15
+1668,15 
/// <param name="sFileName">Name of file
to combine with numbers when generating counted file
names</param>
/// <param name="sFileNumbers">Comma
separated list of numbers for counted file
names</param>
/// <returns></returns>
- private ArrayList MakeTestDataFromString( string
sFileName, string sFileNumbers )
+ private static ArrayList MakeTestDataFromString(string
sFileName, string sFileNumbers)
{
ArrayList alFiles = new ArrayList();
- string[] sNumbers = sFileNumbers.Split( ',' );
- foreach( string sNumber in sNumbers )
+ string[] sNumbers = sFileNumbers.Split(',');
+ foreach(string sNumber in sNumbers)
{
- Int32 iValue = Int32.Parse( sNumber.Trim() );
- alFiles.Add( MakeFileName(sFileName, iValue) );
+ Int32 iValue = Int32.Parse(sNumber.Trim());
+ alFiles.Add(MakeFileName(sFileName, iValue));
}
return alFiles;
 -1631,18
+1686,20 
/// Tests that the current backup index is correctly
detected
/// for a file with no extension
/// </summary>
- [Test] public void TestInitializeRollBackups2()
+ [Test]
+ public void TestInitializeRollBackups2()
{
- VerifyInitializeRollBackupsFromBaseFile(
"LogFile" );
+ VerifyInitializeRollBackupsFromBaseFile("LogFile&qu
ot;);
}
/// <summary>
/// Tests that the current backup index is correctly
detected
/// for a file with a .log extension
/// </summary>
- [Test] public void TestInitializeRollBackups3()
+ [Test]
+ public void TestInitializeRollBackups3()
{
- VerifyInitializeRollBackupsFromBaseFile(
"LogFile.log" );
+ VerifyInitializeRollBackupsFromBaseFile("LogFile.lo
g");
}
/// <summary>
 -1655,30
+1712,30 
{
string sBaseFile = "LogFile.log";
ArrayList arrFiles = new ArrayList();
- arrFiles.Add( "junk1" );
- for( int i=0; i<iBackups; i++ )
+ arrFiles.Add("junk1");
+ for(int i = 0; i < iBackups; i++)
{
- arrFiles.Add( MakeFileName(sBaseFile, i) );
+ arrFiles.Add(MakeFileName(sBaseFile, i));
}
RollingFileAppender rfa = new RollingFileAppender();
rfa.RollingStyle =
RollingFileAppender.RollingMode.Size;
SetFieldMaxSizeRollBackups(rfa, iMaxSizeRollBackups);
SetFieldCurSizeRollBackups(rfa, 0);
- InitializeRollBackups( rfa, sBaseFile, arrFiles );
+ InitializeRollBackups(rfa, sBaseFile, arrFiles);
// iBackups / Meaning
// 0 = none
// 1 = file.log
// 2 = file.log.1
// 3 = file.log.2
- if (0 == iBackups ||
- 1 == iBackups )
+ if (0 == iBackups ||
+ 1 == iBackups)
{
- Assert.AreEqual( 0, GetFieldCurSizeRollBackups(rfa) );
- }
- else
+ Assert.AreEqual(0, GetFieldCurSizeRollBackups(rfa));
+ }
+ else
{
- Assert.AreEqual( Math.Min( iBackups-1,
iMaxSizeRollBackups), GetFieldCurSizeRollBackups(rfa) );
+ Assert.AreEqual(Math.Min(iBackups - 1,
iMaxSizeRollBackups), GetFieldCurSizeRollBackups(rfa));
}
}
 -1686,25
+1743,26 
/// Tests that the current backup index is correctly
detected,
/// and gets no bigger than the max backups setting
/// </summary>
- [Test] public void TestInitializeRollBackups4()
+ [Test]
+ public void TestInitializeRollBackups4()
{
const int iMaxRollBackups = 5;
- VerifyInitializeRollBackups( 0, iMaxRollBackups );
- VerifyInitializeRollBackups( 1, iMaxRollBackups );
- VerifyInitializeRollBackups( 2, iMaxRollBackups );
- VerifyInitializeRollBackups( 3, iMaxRollBackups );
- VerifyInitializeRollBackups( 4, iMaxRollBackups );
- VerifyInitializeRollBackups( 5, iMaxRollBackups );
- VerifyInitializeRollBackups( 6, iMaxRollBackups );
+ VerifyInitializeRollBackups(0, iMaxRollBackups);
+ VerifyInitializeRollBackups(1, iMaxRollBackups);
+ VerifyInitializeRollBackups(2, iMaxRollBackups);
+ VerifyInitializeRollBackups(3, iMaxRollBackups);
+ VerifyInitializeRollBackups(4, iMaxRollBackups);
+ VerifyInitializeRollBackups(5, iMaxRollBackups);
+ VerifyInitializeRollBackups(6, iMaxRollBackups);
// Final we cap out at the max value
- VerifyInitializeRollBackups( 7, iMaxRollBackups );
- VerifyInitializeRollBackups( 8, iMaxRollBackups );
+ VerifyInitializeRollBackups(7, iMaxRollBackups);
+ VerifyInitializeRollBackups(8, iMaxRollBackups);
}
/// <summary>
///
/// </summary>
- [Test,Ignore("Not Implemented: Want to test counted
files limited up, to see that others are ?? ignored?
deleted?")]
+ [Test, Ignore("Not Implemented: Want to test counted
files limited up, to see that others are ?? ignored?
deleted?")]
public void TestInitialization3()
{
}
 -1712,7
+1770,7 
/// <summary>
///
/// </summary>
- [Test,Ignore("Not Implemented: Want to test counted
files limited down, to see that others are ?? ignored?
deleted?")]
+ [Test, Ignore("Not Implemented: Want to test counted
files limited down, to see that others are ?? ignored?
deleted?")]
public void TestInitialization4()
{
}
 -1720,7
+1778,7 
/// <summary>
///
/// </summary>
- [Test,Ignore("Not Implemented: Want to test dated
files with a limit, to see that others are ?? ignored?
deleted?")]
+ [Test, Ignore("Not Implemented: Want to test dated
files with a limit, to see that others are ?? ignored?
deleted?")]
public void TestInitialization5()
{
}
 -1728,7
+1786,7 
/// <summary>
///
/// </summary>
- [Test,Ignore("Not Implemented: Want to test dated
files with no limit, to see that others are ?? ignored?
deleted?")]
+ [Test, Ignore("Not Implemented: Want to test dated
files with no limit, to see that others are ?? ignored?
deleted?")]
public void TestInitialization6()
{
}
 -1736,7
+1794,7 
/// <summary>
///
/// </summary>
- [Test,Ignore("Not Implemented: Want to test dated
files with mixed dates existing, to see that other dates do
not matter")]
+ [Test, Ignore("Not Implemented: Want to test dated
files with mixed dates existing, to see that other dates do
not matter")]
public void TestInitialization7()
{
}
 -1749,34
+1807,37 
private static ArrayList GetExistingFiles(string
baseFilePath)
{
RollingFileAppender appender = new
RollingFileAppender();
- appender.SecurityContext =
log4net.Util.NullSecurityContext.Instance;
+ appender.SecurityContext =
NullSecurityContext.Instance;
return (ArrayList)Utils.InvokeMethod(appender,
"GetExistingFiles", baseFilePath);
}
- private void InitializeRollBackups(RollingFileAppender
appender, string baseFile, ArrayList arrayFiles)
+ private static void
InitializeRollBackups(RollingFileAppender appender, string
baseFile, ArrayList arrayFiles)
{
Utils.InvokeMethod(appender,
"InitializeRollBackups", baseFile, arrayFiles);
}
- private int
GetFieldCurSizeRollBackups(RollingFileAppender appender)
+ private static int
GetFieldCurSizeRollBackups(RollingFileAppender appender)
{
return (int)Utils.GetField(appender,
"m_curSizeRollBackups");
}
- private void
SetFieldCurSizeRollBackups(RollingFileAppender appender, int
val)
+ private static void
SetFieldCurSizeRollBackups(RollingFileAppender appender, int
val)
{
Utils.SetField(appender,
"m_curSizeRollBackups", val);
}
- private void
SetFieldMaxSizeRollBackups(RollingFileAppender appender, int
val)
+
+ private static void
SetFieldMaxSizeRollBackups(RollingFileAppender appender, int
val)
{
Utils.SetField(appender,
"m_maxSizeRollBackups", val);
}
}
- [TestFixture] public class RollingFileAppenderSubClassTest
: RollingFileAppender
+ [TestFixture]
+ public class RollingFileAppenderSubClassTest :
RollingFileAppender
{
- [Test] public void TestComputeCheckPeriod()
+ [Test]
+ public void TestComputeCheckPeriod()
{
RollingFileAppender rfa = new RollingFileAppender();
 -1790,10
+1851,9 
Assert.AreEqual(RollPoint.InvalidRollPoint,
InvokeComputeCheckPeriod(rfa, "..."),
"TopOfMonth pattern");
}
- private static RollPoint
InvokeComputeCheckPeriod(RollingFileAppender
rollingFileAppender, string datePattern)
+ private static RollPoint
InvokeComputeCheckPeriod(RollingFileAppender
rollingFileAppender, string datePattern)
{
return
(RollPoint)Utils.InvokeMethod(rollingFileAppender,
"ComputeCheckPeriod", datePattern);
}
}
-
-}
+}
No newline at end of file
Modified:
logging/log4net/trunk/tests/src/Appender/StringAppender.cs
URL: http://svn.apache.org/viewvc/log
ging/log4net/trunk/tests/src/Appender/StringAppender.cs?view
=diff&rev=511537&r1=511536&r2=511537
============================================================
==================
---
logging/log4net/trunk/tests/src/Appender/StringAppender.cs
(original)
+++
logging/log4net/trunk/tests/src/Appender/StringAppender.cs
Sun Feb 25 08:14:29 2007
 -19,8
+19,8 
using System.Text;
-using log4net.Core;
using log4net.Appender;
+using log4net.Core;
namespace log4net.Tests.Appender
{
 -59,18
+59,18 
/// <summary>
/// </summary>
/// <param name="loggingEvent">the event
to log</param>
- override protected void Append(LoggingEvent loggingEvent)
+ protected override void Append(LoggingEvent
loggingEvent)
{
m_buf.Append(RenderLoggingEvent(loggingEvent));
- }
+ }
/// <summary>
/// This appender requires a <see
cref="Layout"/> to be set.
/// </summary>
/// <value><c>true</c></value>
- override protected bool RequiresLayout
+ protected override bool RequiresLayout
{
get { return true; }
}
}
-}
+}
No newline at end of file
Modified: logging/log4net/trunk/tests/src/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/logging/log4ne
t/trunk/tests/src/AssemblyInfo.cs?view=diff&rev=511537&a
mp;r1=511536&r2=511537
============================================================
==================
--- logging/log4net/trunk/tests/src/AssemblyInfo.cs
(original)
+++ logging/log4net/trunk/tests/src/AssemblyInfo.cs Sun Feb
25 08:14:29 2007
 -18,8
+18,6 
#endregion
using System.Reflection;
-using System.Runtime.CompilerServices;
-
//
// General Information about an assembly is controlled
through the following
// set of attributes. Change these attribute values to
modify the information
 -27,10
+25,8 
//
[assembly: AssemblyTitle("log4net.Tests")]
-
[assembly: AssemblyDescription("Unit Tests for
log4net")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("log4net")]
[assembly: AssemblyDefaultAlias("log4net")]
-[assembly: AssemblyCulture("")]
-
+[assembly: AssemblyCulture("")]
No newline at end of file
Modified:
logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs
URL: http://svn.apache.org/viewvc/l
ogging/log4net/trunk/tests/src/Context/ThreadContextTest.cs?
view=diff&rev=511537&r1=511536&r2=511537
============================================================
==================
---
logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs
(original)
+++
logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs
Sun Feb 25 08:14:29 2007
 -18,15
+18,14 
#endregion
using System;
-using System.Collections;
using System.Threading;
+
using log4net.Config;
-using log4net.Core;
using log4net.Layout;
using log4net.Repository;
-
using log4net.Tests.Appender;
using log4net.Util;
+
using NUnit.Framework;
namespace log4net.Tests.Context
 -37,9
+36,11 
/// <remarks>
/// Used for internal unit testing the <see
cref="ThreadContext"/> class.
/// </remarks>
- [TestFixture] public class ThreadContextTest
+ [TestFixture]
+ public class ThreadContextTest
{
- [Test] public void TestThreadPropertiesPattern()
+ [Test]
+ public void TestThreadPropertiesPattern()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new
PatternLayout("%property");
 -66,7
+67,8 
stringAppender.Reset();
}
- [Test] public void TestThreadStackPattern()
+ [Test]
+ public void TestThreadStackPattern()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new
PatternLayout("%property");
 -92,7
+94,8 
stringAppender.Reset();
}
- [Test] public void TestThreadStackPattern2()
+ [Test]
+ public void TestThreadStackPattern2()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new
PatternLayout("%property");
 -125,7
+128,8 
stringAppender.Reset();
}
- [Test] public void TestThreadStackPatternNullVal()
+ [Test]
+ public void TestThreadStackPatternNullVal()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new
PatternLayout("%property");
 -151,7
+155,8 
stringAppender.Reset();
}
- [Test] public void TestThreadStackPatternNullVal2()
+ [Test]
+ public void TestThreadStackPatternNullVal2()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new
PatternLayout("%property");
 -184,7
+189,8 
stringAppender.Reset();
}
- [Test] public void TestBackgroundThreadContextProperty()
+ [Test]
+ public void TestBackgroundThreadContextProperty()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new
PatternLayout("%property");
 -192,31
+198,23 
ILoggerRepository rep =
LogManager.CreateRepository("TestBackgroundThreadContex
tPropertyRepository");
BasicConfigurator.Configure(rep, stringAppender);
- Thread thread = new Thread(new
ThreadStart(executeBackgroundThread));
+ Thread thread = new Thread(new
ThreadStart(ExecuteBackgroundThread));
thread.Start();
Thread.CurrentThread.Join(2000);
}
- private void executeBackgroundThread()
+ private static void ExecuteBackgroundThread()
{
- ILog log = LogManager.GetLogger(
- "TestBackgroundThreadContextPropertyRepository&quo
t;,
- "ExecuteBackGroundThread");
-
+ ILog log =
LogManager.GetLogger("TestBackgroundThreadContextProper
tyRepository", "ExecuteBackGroundThread");
ThreadContext.Properties["DateTimeTodayToString&quo
t;] = DateTime.Today.ToString();
-
+
log.Info("TestMessage");
- Repository.Hierarchy.Hierarchy
hierarchyLoggingRepository =
- (Repository.Hierarchy.Hierarchy)log.Logger.Repository;
-
- StringAppender stringAppender =
- (StringAppender)hierarchyLoggingRepository.Root.Appende
rs[0];
+ Repository.Hierarchy.Hierarchy
hierarchyLoggingRepository =
(Repository.Hierarchy.Hierarchy)log.Logger.Repository;
+ StringAppender stringAppender =
(StringAppender)hierarchyLoggingRepository.Root.Appenders[0]
;
Assert.AreEqual(DateTime.Today.ToString(),
stringAppender.GetString());
}
-
-
}
-}
+}
No newline at end of file
Modified:
logging/log4net/trunk/tests/src/Core/FixingTest.cs
URL: http://svn.apache.org/viewvc/logging/log
4net/trunk/tests/src/Core/FixingTest.cs?view=diff&rev=51
1537&r1=511536&r2=511537
============================================================
==================
--- logging/log4net/trunk/tests/src/Core/FixingTest.cs
(original)
+++ logging/log4net/trunk/tests/src/Core/FixingTest.cs Sun
Feb 25 08:14:29 2007
 -19,6
+19,7 
using System;
using System.Threading;
+
using log4net.Core;
using NUnit.Framework;
 -27,7
+28,8 
{
/// <summary>
/// </<summary>
- [TestFixture] public class FixingTest
+ [TestFixture]
+ public class FixingTest
{
static FixingTest()
{
 -40,10
+42,11 
}
}
- [Test] public void TestUnfixedValues()
+ [Test]
+ public void TestUnfixedValues()
{
- LoggingEventData loggingEventData =
buildStandardEventData();
-
+ LoggingEventData loggingEventData =
BuildStandardEventData();
+
// LoggingEvents occur at distinct points in time
LoggingEvent loggingEvent = new LoggingEvent(
loggingEventData.LocationInfo.GetType(),
 -53,15
+56,16 
loggingEventData.Message,
new Exception("This is the exception"));
- assertExpectedLoggingEvent(loggingEvent,
loggingEventData);
+ AssertExpectedLoggingEvent(loggingEvent,
loggingEventData);
- Assert.AreEqual(FixFlags.None,loggingEvent.Fix,"Fix
ed Fields is incorrect");
+ Assert.AreEqual(FixFlags.None, loggingEvent.Fix,
"Fixed Fields is incorrect");
}
- [Test] public void TestAllFixedValues()
+ [Test]
+ public void TestAllFixedValues()
{
- LoggingEventData loggingEventData =
buildStandardEventData();
-
+ LoggingEventData loggingEventData =
BuildStandardEventData();
+
// LoggingEvents occur at distinct points in time
LoggingEvent loggingEvent = new LoggingEvent(
loggingEventData.LocationInfo.GetType(),
 -71,17
+75,18 
loggingEventData.Message,
new Exception("This is the exception"));
- assertExpectedLoggingEvent(loggingEvent,
loggingEventData);
+ AssertExpectedLoggingEvent(loggingEvent,
loggingEventData);
loggingEvent.Fix = FixFlags.All;
- Assert.AreEqual(FixFlags.LocationInfo|
FixFlags.UserName| FixFlags.Identity|
FixFlags.Partial|FixFlags.Message | FixFlags.ThreadName |
FixFlags.Exception | FixFlags.Domain |
FixFlags.Properties,loggingEvent.Fix,"Fixed Fields is
incorrect");
+ Assert.AreEqual(FixFlags.LocationInfo |
FixFlags.UserName | FixFlags.Identity | FixFlags.Partial |
FixFlags.Message | FixFlags.ThreadName | FixFlags.Exception
| FixFlags.Domain | FixFlags.Properties, loggingEvent.Fix,
"Fixed Fields is incorrect");
}
- [Test] public void TestNoFixedValues()
+ [Test]
+ public void TestNoFixedValues()
{
- LoggingEventData loggingEventData =
buildStandardEventData();
-
+ LoggingEventData loggingEventData =
BuildStandardEventData();
+
// LoggingEvents occur at distinct points in time
LoggingEvent loggingEvent = new LoggingEvent(
loggingEventData.LocationInfo.GetType(),
 -91,21
+96,21 
loggingEventData.Message,
new Exception("This is the exception"));
- assertExpectedLoggingEvent(loggingEvent,
loggingEventData);
+ AssertExpectedLoggingEvent(loggingEvent,
loggingEventData);
loggingEvent.Fix = FixFlags.None;
- Assert.AreEqual(FixFlags.None,loggingEvent.Fix,"Fix
ed Fields is incorrect");
+ Assert.AreEqual(FixFlags.None, loggingEvent.Fix,
"Fixed Fields is incorrect");
}
- private LoggingEventData buildStandardEventData()
+ private static LoggingEventData BuildStandardEventData()
{
LoggingEventData loggingEventData = new
LoggingEventData();
loggingEventData.LoggerName =
typeof(FixingTest).FullName;
loggingEventData.Level = Level.Warn;
loggingEventData.Message = "Logging event
works";
loggingEventData.Domain = "ReallySimpleApp";
- loggingEventData.LocationInfo = new
LocationInfo(typeof(FixingTest).Name,"Main","
Class1.cs","29"); //Completely arbitary
+ loggingEventData.LocationInfo = new
LocationInfo(typeof(FixingTest).Name, "Main",
"Class1.cs", "29"); //Completely
arbitary
loggingEventData.ThreadName =
Thread.CurrentThread.Name;
loggingEventData.TimeStamp = DateTime.Today;
loggingEventData.ExceptionString = "Exception
occured here";
 -113,19
+118,19 
return loggingEventData;
}
- private void assertExpectedLoggingEvent(LoggingEvent
loggingEvent, LoggingEventData loggingEventData)
+ private static void
AssertExpectedLoggingEvent(LoggingEvent loggingEvent,
LoggingEventData loggingEventData)
{
- Assert.AreEqual("ReallySimpleApp",loggingEvent
Data.Domain,"Domain is incorrect");
- Assert.AreEqual("System.Exception: This is the
exception",loggingEvent.GetExceptionString(),"Exce
ption is incorrect");
- Assert.AreEqual(null,loggingEventData.Identity,"Ide
ntity is incorrect");
- Assert.AreEqual(Level.Warn,loggingEventData.Level,"
Level is incorrect");
- Assert.AreEqual("get_LocationInformation",logg
ingEvent.LocationInformation.MethodName,"Location Info
is incorrect");
- Assert.AreEqual("log4net.Tests.Core.FixingTest"
;,loggingEventData.LoggerName,"LoggerName is
incorrect");
- Assert.AreEqual(LogManager.GetRepository("Test
Repository"),loggingEvent.Repository,"Repository
is incorrect");
- Assert.AreEqual(Thread.CurrentThread.Name,loggingEventDa
ta.ThreadName,"ThreadName is incorrect");
- Assert.IsNotNull(loggingEventData.TimeStamp,"TimeSt
amp is incorrect");
- Assert.AreEqual("TestUser"
,loggingEventData.UserName,"UserName is
incorrect");
- Assert.AreEqual("Logging event
works",loggingEvent.RenderedMessage,"Message is
incorrect");
+ Assert.AreEqual("ReallySimpleApp",
loggingEventData.Domain, "Domain is incorrect");
+ Assert.AreEqual("System.Exception: This is the
exception", loggingEvent.GetExceptionString(),
"Exception is incorrect");
+ Assert.AreEqual(null, loggingEventData.Identity,
"Identity is incorrect");
+ Assert.AreEqual(Level.Warn, loggingEventData.Level,
"Level is incorrect");
+ Assert.AreEqual("get_LocationInformation",
loggingEvent.LocationInformation.MethodName, "Location
Info is incorrect");
+ Assert.AreEqual("log4net.Tests.Core.FixingTest"
;, loggingEventData.LoggerName, "LoggerName is
incorrect");
+ Assert.AreEqual(LogManager.GetRepository("Test
Repository"), loggingEvent.Repository, "Repository
is incorrect");
+ Assert.AreEqual(Thread.CurrentThread.Name,
loggingEventData.ThreadName, "ThreadName is
incorrect");
+ Assert.IsNotNull(loggingEventData.TimeStamp,
"TimeStamp is incorrect");
+ Assert.AreEqual("TestUser",
loggingEventData.UserName, "UserName is
incorrect");
+ Assert.AreEqual("Logging event works",
loggingEvent.RenderedMessage, "Message is
incorrect");
}
}
-}
+}
No newline at end of file
Modified:
logging/log4net/trunk/tests/src/Core/ShutdownTest.cs
URL: http://svn.apache.org/viewvc/logging/l
og4net/trunk/tests/src/Core/ShutdownTest.cs?view=diff&re
v=511537&r1=511536&r2=511537
============================================================
==================
--- logging/log4net/trunk/tests/src/Core/ShutdownTest.cs
(original)
+++ logging/log4net/trunk/tests/src/Core/ShutdownTest.cs Sun
Feb 25 08:14:29 2007
 -30,12
+30,14 
{
/// <summary>
/// </remarks>
- [TestFixture] public class ShutdownTest
+ [TestFixture]
+ public class ShutdownTest
{
/// <summary>
/// Test that a repository can be shutdown and
reconfigured
/// </summary>
- [Test] public void TestShutdownAndReconfigure()
+ [Test]
+ public void TestShutdownAndReconfigure()
{
// Create unique repository
ILoggerRepository rep =
LogManager.CreateRepository(Guid.NewGuid().ToString());
 -68,4
+70,4 
stringAppender.Reset();
}
}
-}
+}
No newline at end of file
|