nicko 2004/02/26 13:08:49
Modified: tests/src log4net.Tests.csproj
tests/src/Appender EventLogAppenderTest.cs
RollingFileAppenderTest.cs
tests/src/Hierarchy Logger.cs
Added: tests/src Utils.cs
tests/src/Appender CountingAppender.cs StringAppender.cs
tests/src/Layout PatternLayoutTest.cs
Log:
Updated to use GetRepository. Renamed Util to Utils
Revision Changes Path
1.2 +19 -3 logging-log4net/tests/src/log4net.Tests.csproj
Index: log4net.Tests.csproj
===================================================================
RCS file: /home/cvs/logging-log4net/tests/src/log4net.Tests.csproj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- log4net.Tests.csproj 16 Feb 2004 16:30:04 -0000 1.1
+++ log4net.Tests.csproj 26 Feb 2004 21:08:49 -0000 1.2
@@ -31,7 +31,7 @@
FileAlignment = "4096"
IncrementalBuild = "true"
Optimize = "false"
- OutputPath = "bin\Debug\"
+ OutputPath = "..\bin\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
@@ -49,7 +49,7 @@
FileAlignment = "4096"
IncrementalBuild = "false"
Optimize = "true"
- OutputPath = "bin\Release\"
+ OutputPath = "..\bin\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
@@ -94,10 +94,16 @@
<File
RelPath = "AssemblyVersionInfo.cs"
Link = "..\..\src\AssemblyVersionInfo.cs"
+ SubType = "Code"
BuildAction = "Compile"
/>
<File
- RelPath = "Util.cs"
+ RelPath = "Utils.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Appender\CountingAppender.cs"
SubType = "Code"
BuildAction = "Compile"
/>
@@ -112,7 +118,17 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Appender\StringAppender.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Hierarchy\Logger.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Layout\PatternLayoutTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
1.1 logging-log4net/tests/src/Utils.cs
Index: Utils.cs
===================================================================
#region Copyright & License
//
// Copyright 2001-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System;
using System.Reflection;
namespace log4net.Tests
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Utils
{
public Utils()
{
}
public static object InvokeMethod(object target, string name,
params object[] args)
{
return target.GetType().GetMethod(name,
BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Static|BindingFlags.Instance).Invoke(target,
args);
}
public static object InvokeMethod(Type target, string name,
params object[] args)
{
return target.GetMethod(name,
BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Static).Invoke(null,
args);
}
public static object GetField(object target, string name)
{
return target.GetType().GetField(name,
BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Static|BindingFlags.Instance).GetValue(target);
}
public static void SetField(object target, string name, object
val)
{
target.GetType().GetField(name,
BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Static|BindingFlags.Instance).SetValue(target,
val);
}
}
}
1.2 +1 -1
logging-log4net/tests/src/Appender/EventLogAppenderTest.cs
Index: EventLogAppenderTest.cs
===================================================================
RCS file:
/home/cvs/logging-log4net/tests/src/Appender/EventLogAppenderTest.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventLogAppenderTest.cs 16 Feb 2004 16:30:04 -0000 1.1
+++ EventLogAppenderTest.cs 26 Feb 2004 21:08:49 -0000 1.2
@@ -81,7 +81,7 @@
private static System.Diagnostics.EventLogEntryType
GetEntryType(EventLogAppender appender, Level level)
{
- return
(System.Diagnostics.EventLogEntryType)Util.InvokeMethod(appender,
"GetEntryType", level);
+ return
(System.Diagnostics.EventLogEntryType)Utils.InvokeMethod(appender,
"GetEntryType", level);
}
}
}
1.2 +9 -9
logging-log4net/tests/src/Appender/RollingFileAppenderTest.cs
Index: RollingFileAppenderTest.cs
===================================================================
RCS file:
/home/cvs/logging-log4net/tests/src/Appender/RollingFileAppenderTest.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RollingFileAppenderTest.cs 16 Feb 2004 16:30:04 -0000 1.1
+++ RollingFileAppenderTest.cs 26 Feb 2004 21:08:49 -0000 1.2
@@ -67,9 +67,9 @@
private void ResetAndDeleteTestFiles()
{
// Regular users should not use the clear method
lightly!
- LogManager.GetLoggerRepository().ResetConfiguration();
- LogManager.GetLoggerRepository().Shutdown();
-
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository()).Clear();
+ LogManager.GetRepository().ResetConfiguration();
+ LogManager.GetRepository().Shutdown();
+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Clear();
DeleteTestFiles();
}
@@ -1044,7 +1044,7 @@
/// </summary>
private void ConfigureRootAppender()
{
- _root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository()).Root;
+ _root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
_root.Level = Level.Debug;
_caRoot = new CountingAppender();
_root.AddAppender(_caRoot);
@@ -1493,26 +1493,26 @@
private static ArrayList GetExistingFiles(string baseFilePath)
{
- return
(ArrayList)Util.InvokeMethod(typeof(RollingFileAppender), "GetExistingFiles",
baseFilePath);
+ return
(ArrayList)Utils.InvokeMethod(typeof(RollingFileAppender), "GetExistingFiles",
baseFilePath);
}
private void InitializeRollBackups(RollingFileAppender
appender, string baseFile, ArrayList arrayFiles)
{
- Util.InvokeMethod(appender, "InitializeRollBackups",
baseFile, arrayFiles);
+ Utils.InvokeMethod(appender, "InitializeRollBackups",
baseFile, arrayFiles);
}
private int GetFieldCurSizeRollBackups(RollingFileAppender
appender)
{
- return (int)Util.GetField(appender,
"m_curSizeRollBackups");
+ return (int)Utils.GetField(appender,
"m_curSizeRollBackups");
}
private void SetFieldCurSizeRollBackups(RollingFileAppender
appender, int val)
{
- Util.SetField(appender, "m_curSizeRollBackups", val);
+ Utils.SetField(appender, "m_curSizeRollBackups", val);
}
private void SetFieldMaxSizeRollBackups(RollingFileAppender
appender, int val)
{
- Util.SetField(appender, "m_maxSizeRollBackups", val);
+ Utils.SetField(appender, "m_maxSizeRollBackups", val);
}
}
}
1.1 logging-log4net/tests/src/Appender/CountingAppender.cs
Index: CountingAppender.cs
===================================================================
#region Copyright & License
//
// Copyright 2001-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using log4net.Layout;
using log4net.Core;
using log4net.Appender;
namespace log4net.Tests.Appender
{
/// <summary>
/// Implements an Appender for test purposes that counts the
/// number of output calls to <see cref="Append" />.
/// </summary>
/// <remarks>
/// This appender is used in the unit tests.
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
public class CountingAppender : AppenderSkeleton
{
#region Public Instance Constructors
/// <summary>
/// Initializes a new instance of the <see
cref="CountingAppender" /> class.
/// </summary>
public CountingAppender()
{
m_counter = 0;
}
#endregion Public Instance Constructors
#region Public Instance Properties
/// <summary>
/// Returns the number of times <see cref="Append" /> has been
called.
/// </summary>
/// <value>
/// The number of times <see cref="Append" /> has been called.
/// </value>
public int Counter
{
get { return m_counter; }
}
#endregion Public Instance Properties
#region Override implementation of AppenderSkeleton
/// <summary>
/// Registers how many times the method has been called.
/// </summary>
/// <param name="logEvent">The logging event.</param>
override protected void Append(LoggingEvent logEvent)
{
m_counter++;
}
#endregion Override implementation of AppenderSkeleton
#region Private Instance Fields
/// <summary>
/// The number of times <see cref="Append" /> has been called.
/// </summary>
private int m_counter;
#endregion Private Instance Fields
}
}
1.1 logging-log4net/tests/src/Appender/StringAppender.cs
Index: StringAppender.cs
===================================================================
#region Copyright & License
//
// Copyright 2001-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System.Text;
using System.Runtime.InteropServices;
using log4net.Layout;
using log4net.Core;
using log4net.Appender;
namespace log4net.Tests.Appender
{
/// <summary>
/// Write events to a string
/// </summary>
/// <author>Nicko Cadell</author>
public class StringAppender : AppenderSkeleton
{
private StringBuilder m_buf = new StringBuilder();
/// <summary>
/// Initializes a new instance of the <see
cref="StringAppender" /> class.
/// </summary>
public StringAppender()
{
}
/// <summary>
/// Get the string logged so far
/// </summary>
/// <returns></returns>
public string GetString()
{
return m_buf.ToString();
}
/// <summary>
/// Reset the string
/// </summary>
public void Reset()
{
m_buf.Length = 0;
}
/// <summary>
/// </summary>
/// <param name="loggingEvent">the event to log</param>
override protected 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
{
get { return true; }
}
}
}
1.2 +7 -6 logging-log4net/tests/src/Hierarchy/Logger.cs
Index: Logger.cs
===================================================================
RCS file: /home/cvs/logging-log4net/tests/src/Hierarchy/Logger.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Logger.cs 16 Feb 2004 16:30:04 -0000 1.1
+++ Logger.cs 26 Feb 2004 21:08:49 -0000 1.2
@@ -24,6 +24,7 @@
using log4net.Core;
using log4net.Repository;
using log4net.Repository.Hierarchy;
+using log4net.Tests.Appender;
using NUnit.Framework;
@@ -57,9 +58,9 @@
[TearDown] public void TearDown()
{
// Regular users should not use the clear method
lightly!
- LogManager.GetLoggerRepository().ResetConfiguration();
- LogManager.GetLoggerRepository().Shutdown();
-
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository()).Clear();
+ LogManager.GetRepository().ResetConfiguration();
+ LogManager.GetRepository().Shutdown();
+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Clear();
}
/// <summary>
@@ -168,7 +169,7 @@
/// </summary>
[Test] public void TestAdditivity3()
{
- Logger root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository()).Root;
+ Logger root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
Logger a = LogManager.GetLogger("a").Logger as Logger;
Logger ab = LogManager.GetLogger("a.b").Logger as
Logger;
Logger abc = LogManager.GetLogger("a.b.c").Logger as
Logger;
@@ -211,10 +212,10 @@
[Test] public void TestDisable1()
{
CountingAppender caRoot = new CountingAppender();
- Logger root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository()).Root;
+ Logger root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
root.AddAppender(caRoot);
- log4net.Repository.Hierarchy.Hierarchy h =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository());
+ log4net.Repository.Hierarchy.Hierarchy h =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository());
h.Threshold = Level.Info;
h.Configured = true;
1.1 logging-log4net/tests/src/Layout/PatternLayoutTest.cs
Index: PatternLayoutTest.cs
===================================================================
#region Copyright & License
//
// Copyright 2001-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using log4net.Config;
using log4net.Util;
using log4net.Layout;
using log4net.Core;
using log4net.Appender;
using log4net.Repository;
using log4net.Tests.Appender;
using NUnit.Framework;
namespace log4net.Tests.Layout
{
/// <summary>
/// Used for internal unit testing the <see cref="PatternLayoutTest"/>
class.
/// </summary>
/// <remarks>
/// Used for internal unit testing the <see cref="PatternLayoutTest"/>
class.
/// </remarks>
[TestFixture] public class PatternLayoutTest
{
[Test] public void TestMdcPattern()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new
PatternLayout("%mdc{prop1}");
ILoggerRepository rep =
LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
ILog log1 = LogManager.GetLogger(rep.Name,
"TestMdcPattern");
log1.Info("TestMessage");
Assertion.AssertEquals("Test no mdc value set",
"(null)", stringAppender.GetString());
stringAppender.Reset();
MDC.Set("prop1", "val1");
log1.Info("TestMessage");
Assertion.AssertEquals("Test thread mdc value set",
"val1", stringAppender.GetString());
stringAppender.Reset();
MDC.Remove("prop1");
log1.Info("TestMessage");
Assertion.AssertEquals("Test mdc value removed",
"(null)", stringAppender.GetString());
stringAppender.Reset();
}
}
}