4
4
5
5
using NHibernate . Cfg . ConfigurationSchema ;
6
6
using NUnit . Framework ;
7
+ using log4net . Repository . Hierarchy ;
7
8
8
9
namespace NHibernate . Test
9
10
{
@@ -13,15 +14,43 @@ public class TestsContext
13
14
[ OneTimeSetUp ]
14
15
public void RunBeforeAnyTests ( )
15
16
{
17
+ HibernateConfiguration config = GetTestAssemblyHibernateConfiguration ( ) ;
18
+ NHibernate . Cfg . Environment . InitializeGlobalProperties ( config ) ;
19
+
20
+ ConfigureLog4Net ( ) ;
21
+ }
22
+
23
+ public static HibernateConfiguration GetTestAssemblyHibernateConfiguration ( )
24
+ {
25
+ HibernateConfiguration config ;
16
26
string assemblyPath = Path . Combine ( TestContext . CurrentContext . TestDirectory , @"NHibernate.Test.dll" ) ;
17
27
var configuration = ConfigurationManager . OpenExeConfiguration ( assemblyPath ) ;
18
28
ConfigurationSection configSection = configuration . GetSection ( CfgXmlHelper . CfgSectionName ) ;
19
29
20
30
using ( XmlTextReader reader = new XmlTextReader ( configSection . SectionInformation . GetRawXml ( ) , XmlNodeType . Document , null ) )
21
31
{
22
- HibernateConfiguration config = new HibernateConfiguration ( reader ) ;
23
- NHibernate . Cfg . Environment . InitializeGlobalProperties ( config ) ;
32
+ config = new HibernateConfiguration ( reader ) ;
24
33
}
34
+
35
+ return config ;
36
+ }
37
+
38
+ private static void ConfigureLog4Net ( )
39
+ {
40
+ var hierarchy = ( Hierarchy ) log4net . LogManager . GetRepository ( typeof ( TestsContext ) . Assembly ) ;
41
+
42
+ var consoleAppender = new log4net . Appender . ConsoleAppender ( )
43
+ {
44
+ Layout = new log4net . Layout . PatternLayout ( "%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" ) ,
45
+ } ;
46
+
47
+ ( ( Logger ) hierarchy . GetLogger ( "NHibernate.Hql.Ast.ANTLR" ) ) . Level = log4net . Core . Level . Off ;
48
+ ( ( Logger ) hierarchy . GetLogger ( "NHibernate.SQL" ) ) . Level = log4net . Core . Level . Off ;
49
+ ( ( Logger ) hierarchy . GetLogger ( "NHibernate.AdoNet.AbstractBatcher" ) ) . Level = log4net . Core . Level . Off ;
50
+ ( ( Logger ) hierarchy . GetLogger ( "NHibernate.Tool.hbm2ddl.SchemaExport" ) ) . Level = log4net . Core . Level . Error ;
51
+ hierarchy . Root . Level = log4net . Core . Level . Warn ;
52
+ hierarchy . Root . AddAppender ( consoleAppender ) ;
53
+ hierarchy . Configured = true ;
25
54
}
26
55
}
27
56
}
0 commit comments