Skip to content

Commit

Permalink
Merge pull request #157 from apache/Feature/157-fixed-Regression-when…
Browse files Browse the repository at this point in the history
…-creating-nested-loggers-in-reverse-order

#156 fixed Regression when creating nested loggers in reverse order
  • Loading branch information
FreeAndNil authored Jul 29, 2024
2 parents 804c862 + 5f94dcc commit 34b501c
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 559 deletions.
125 changes: 74 additions & 51 deletions src/log4net.Tests/Hierarchy/HierarchyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
using System;
using System.Xml;
using log4net.Config;
using log4net.Core;
using log4net.Repository;
using log4net.Repository.Hierarchy;
using log4net.Tests.Appender;
using NUnit.Framework;

Expand All @@ -39,19 +37,19 @@ public void SetRepositoryPropertiesInConfigFile()
// LOG4NET-53: Allow repository properties to be set in the config file
XmlDocument log4netConfig = new XmlDocument();
log4netConfig.LoadXml(@"
<log4net>
<property>
<key value=""two-plus-two"" />
<value value=""4"" />
</property>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
</log4net>");
<log4net>
<property>
<key value=""two-plus-two"" />
<value value=""4"" />
</property>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
</log4net>");

ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
XmlConfigurator.Configure(rep, log4netConfig["log4net"]!);
Expand Down Expand Up @@ -101,18 +99,18 @@ public void LoggerNameCanConsistOfASingleDot()
{
XmlDocument log4netConfig = new XmlDocument();
log4netConfig.LoadXml(@"
<log4net>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
<logger name=""."">
<level value=""WARN"" />
</logger>
</log4net>");
<log4net>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
<logger name=""."">
<level value=""WARN"" />
</logger>
</log4net>");

ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
XmlConfigurator.Configure(rep, log4netConfig["log4net"]!);
Expand All @@ -123,18 +121,18 @@ public void LoggerNameCanConsistOfASingleNonDot()
{
XmlDocument log4netConfig = new XmlDocument();
log4netConfig.LoadXml(@"
<log4net>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
<logger name=""L"">
<level value=""WARN"" />
</logger>
</log4net>");
<log4net>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
<logger name=""L"">
<level value=""WARN"" />
</logger>
</log4net>");

ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
XmlConfigurator.Configure(rep, log4netConfig["log4net"]!);
Expand All @@ -145,21 +143,46 @@ public void LoggerNameCanContainSequenceOfDots()
{
XmlDocument log4netConfig = new XmlDocument();
log4netConfig.LoadXml(@"
<log4net>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
<logger name=""L..M"">
<level value=""WARN"" />
</logger>
</log4net>");
<log4net>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
<logger name=""L..M"">
<level value=""WARN"" />
</logger>
</log4net>");

ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
XmlConfigurator.Configure(rep, log4netConfig["log4net"]!);
}

/// <summary>
/// https://github.com/apache/logging-log4net/issues/156
/// Regression: Creating nested loggers in reverse order fails in 3.0.0-preview.1
/// </summary>
[Test]
public void CreateNestedLoggersInReverseOrder()
{
XmlDocument log4netConfig = new XmlDocument();
log4netConfig.LoadXml(@"
<log4net>
<appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
<layout type=""log4net.Layout.SimpleLayout"" />
</appender>
<root>
<level value=""ALL"" />
<appender-ref ref=""StringAppender"" />
</root>
</log4net>");

ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
XmlConfigurator.Configure(rep, log4netConfig["log4net"]!);
Assert.AreEqual("A.B.C", rep.GetLogger("A.B.C").Name);
Assert.AreEqual("A.B", rep.GetLogger("A.B").Name);
}
}
}
Loading

0 comments on commit 34b501c

Please sign in to comment.