20
20
*/
21
21
22
22
using System ;
23
+ using System . Threading . Tasks ;
23
24
using System . Xml ;
24
25
using log4net . Config ;
25
26
using log4net . Repository ;
29
30
namespace log4net . Tests . Hierarchy ;
30
31
31
32
[ TestFixture ]
32
- public class Hierarchy
33
+ public class HierarchyTest
33
34
{
34
35
[ Test ]
35
36
public void SetRepositoryPropertiesInConfigFile ( )
36
37
{
37
38
// LOG4NET-53: Allow repository properties to be set in the config file
38
39
XmlDocument log4NetConfig = new ( ) ;
39
40
log4NetConfig . LoadXml ( @"
40
- <log4net>
41
- <property>
42
- <key value=""two-plus-two"" />
43
- <value value=""4"" />
44
- </property>
45
- <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
46
- <layout type=""log4net.Layout.SimpleLayout"" />
47
- </appender>
48
- <root>
49
- <level value=""ALL"" />
50
- <appender-ref ref=""StringAppender"" />
51
- </root>
52
- </log4net>" ) ;
41
+ <log4net>
42
+ <property>
43
+ <key value=""two-plus-two"" />
44
+ <value value=""4"" />
45
+ </property>
46
+ <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
47
+ <layout type=""log4net.Layout.SimpleLayout"" />
48
+ </appender>
49
+ <root>
50
+ <level value=""ALL"" />
51
+ <appender-ref ref=""StringAppender"" />
52
+ </root>
53
+ </log4net>" ) ;
53
54
54
55
ILoggerRepository rep = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
55
56
XmlConfigurator . Configure ( rep , log4NetConfig [ "log4net" ] ! ) ;
@@ -99,18 +100,18 @@ public void LoggerNameCanConsistOfASingleDot()
99
100
{
100
101
XmlDocument log4NetConfig = new ( ) ;
101
102
log4NetConfig . LoadXml ( @"
102
- <log4net>
103
- <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
104
- <layout type=""log4net.Layout.SimpleLayout"" />
105
- </appender>
106
- <root>
107
- <level value=""ALL"" />
108
- <appender-ref ref=""StringAppender"" />
109
- </root>
110
- <logger name=""."">
111
- <level value=""WARN"" />
112
- </logger>
113
- </log4net>" ) ;
103
+ <log4net>
104
+ <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
105
+ <layout type=""log4net.Layout.SimpleLayout"" />
106
+ </appender>
107
+ <root>
108
+ <level value=""ALL"" />
109
+ <appender-ref ref=""StringAppender"" />
110
+ </root>
111
+ <logger name=""."">
112
+ <level value=""WARN"" />
113
+ </logger>
114
+ </log4net>" ) ;
114
115
115
116
ILoggerRepository rep = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
116
117
XmlConfigurator . Configure ( rep , log4NetConfig [ "log4net" ] ! ) ;
@@ -121,18 +122,18 @@ public void LoggerNameCanConsistOfASingleNonDot()
121
122
{
122
123
XmlDocument log4NetConfig = new ( ) ;
123
124
log4NetConfig . LoadXml ( @"
124
- <log4net>
125
- <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
126
- <layout type=""log4net.Layout.SimpleLayout"" />
127
- </appender>
128
- <root>
129
- <level value=""ALL"" />
130
- <appender-ref ref=""StringAppender"" />
131
- </root>
132
- <logger name=""L"">
133
- <level value=""WARN"" />
134
- </logger>
135
- </log4net>" ) ;
125
+ <log4net>
126
+ <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
127
+ <layout type=""log4net.Layout.SimpleLayout"" />
128
+ </appender>
129
+ <root>
130
+ <level value=""ALL"" />
131
+ <appender-ref ref=""StringAppender"" />
132
+ </root>
133
+ <logger name=""L"">
134
+ <level value=""WARN"" />
135
+ </logger>
136
+ </log4net>" ) ;
136
137
137
138
ILoggerRepository rep = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
138
139
XmlConfigurator . Configure ( rep , log4NetConfig [ "log4net" ] ! ) ;
@@ -143,18 +144,18 @@ public void LoggerNameCanContainSequenceOfDots()
143
144
{
144
145
XmlDocument log4NetConfig = new ( ) ;
145
146
log4NetConfig . LoadXml ( @"
146
- <log4net>
147
- <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
148
- <layout type=""log4net.Layout.SimpleLayout"" />
149
- </appender>
150
- <root>
151
- <level value=""ALL"" />
152
- <appender-ref ref=""StringAppender"" />
153
- </root>
154
- <logger name=""L..M"">
155
- <level value=""WARN"" />
156
- </logger>
157
- </log4net>" ) ;
147
+ <log4net>
148
+ <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
149
+ <layout type=""log4net.Layout.SimpleLayout"" />
150
+ </appender>
151
+ <root>
152
+ <level value=""ALL"" />
153
+ <appender-ref ref=""StringAppender"" />
154
+ </root>
155
+ <logger name=""L..M"">
156
+ <level value=""WARN"" />
157
+ </logger>
158
+ </log4net>" ) ;
158
159
159
160
ILoggerRepository rep = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
160
161
XmlConfigurator . Configure ( rep , log4NetConfig [ "log4net" ] ! ) ;
@@ -169,19 +170,44 @@ public void CreateNestedLoggersInReverseOrder()
169
170
{
170
171
XmlDocument log4NetConfig = new ( ) ;
171
172
log4NetConfig . LoadXml ( @"
172
- <log4net>
173
- <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
174
- <layout type=""log4net.Layout.SimpleLayout"" />
175
- </appender>
176
- <root>
177
- <level value=""ALL"" />
178
- <appender-ref ref=""StringAppender"" />
179
- </root>
180
- </log4net>" ) ;
173
+ <log4net>
174
+ <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
175
+ <layout type=""log4net.Layout.SimpleLayout"" />
176
+ </appender>
177
+ <root>
178
+ <level value=""ALL"" />
179
+ <appender-ref ref=""StringAppender"" />
180
+ </root>
181
+ </log4net>" ) ;
181
182
182
183
ILoggerRepository rep = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
183
184
XmlConfigurator . Configure ( rep , log4NetConfig [ "log4net" ] ! ) ;
184
185
Assert . AreEqual ( "A.B.C" , rep . GetLogger ( "A.B.C" ) . Name ) ;
185
186
Assert . AreEqual ( "A.B" , rep . GetLogger ( "A.B" ) . Name ) ;
186
187
}
187
- }
188
+
189
+ /// <summary>
190
+ /// https://github.com/apache/logging-log4net/issues/197
191
+ /// IndexOutOfRangeException when creating child loggers multithreaded
192
+ /// </summary>
193
+ [ Test ]
194
+ public void CreateChildLoggersMultiThreaded ( )
195
+ {
196
+ XmlDocument log4NetConfig = new ( ) ;
197
+ log4NetConfig . LoadXml ( @"
198
+ <log4net>
199
+ <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
200
+ <layout type=""log4net.Layout.SimpleLayout"" />
201
+ </appender>
202
+ <root>
203
+ <level value=""ALL"" />
204
+ <appender-ref ref=""StringAppender"" />
205
+ </root>
206
+ </log4net>" ) ;
207
+
208
+ ILoggerRepository rep = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
209
+ XmlConfigurator . Configure ( rep , log4NetConfig [ "log4net" ] ! ) ;
210
+
211
+ Parallel . For ( 0 , 100 , i => Assert . AreEqual ( $ "A.{ i } ", rep . GetLogger ( $ "A.{ i } ") . Name ) ) ;
212
+ }
213
+ }
0 commit comments