1+ #region Apache License
2+ //
3+ // Licensed to the Apache Software Foundation (ASF) under one or more
4+ // contributor license agreements. See the NOTICE file distributed with
5+ // this work for additional information regarding copyright ownership.
6+ // The ASF licenses this file to you under the Apache License, Version 2.0
7+ // (the "License"); you may not use this file except in compliance with
8+ // the License. You may obtain a copy of the License at
9+ //
10+ // http://www.apache.org/licenses/LICENSE-2.0
11+ //
12+ // Unless required by applicable law or agreed to in writing, software
13+ // distributed under the License is distributed on an "AS IS" BASIS,
14+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ // See the License for the specific language governing permissions and
16+ // limitations under the License.
17+ //
18+ #endregion
19+
20+ using System ;
21+
22+ using log4net . Config ;
23+ using log4net . Layout ;
24+ using log4net . Repository ;
25+ using log4net . Tests . Appender ;
26+
27+ using NUnit . Framework ;
28+
29+ namespace log4net . Tests . Layout
30+ {
31+ /// <summary>
32+ /// Tests for <see cref="XmlLayoutSchemaLog4J"/>
33+ /// </summary>
34+ [ TestFixture ]
35+ public class XmlLayoutSchemaLog4JTest
36+ {
37+ /// <summary>
38+ /// Tests a regression from 3.0.0 (log4j:data instead of log4j:throwable)
39+ /// </summary>
40+ [ Test ]
41+ public void LogExceptionTest ( )
42+ {
43+ StringAppender stringAppender = new ( ) { Layout = new XmlLayoutSchemaLog4J ( ) } ;
44+
45+ ILoggerRepository repository = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
46+ BasicConfigurator . Configure ( repository , stringAppender ) ;
47+ ILog log = LogManager . GetLogger ( repository . Name , "TestLogger" ) ;
48+
49+ ThrowAndLog ( 42 ) ;
50+
51+ string logEventXml = stringAppender . GetString ( ) ;
52+ Assert . That ( logEventXml , Does . Contain ( "log4j:throwable" ) ) ;
53+
54+ void ThrowAndLog ( int foo )
55+ {
56+ try
57+ {
58+ throw new TimeoutException ( ) ;
59+ }
60+ catch ( TimeoutException ex )
61+ {
62+ log . Error ( $ "Error { foo } ", ex ) ;
63+ }
64+ }
65+ }
66+ }
67+ }
0 commit comments