Hibernate version: 1.2.1
I cannot get NH to read from app.config. How do you people do it? It is always looking for hibernate.cfg.xml file in bin directory. So I create cfg file and put it in the roor of the application and make it embeded resource. It is still looking for it in bin directory. So what is going on here?
App.Config file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<!-- This section is for NHibernate configuration-->
<hibernate-configuration>
<!-- an ISessionFactory instance -->
<session-factory xmlns="urn:nhibernate-configuration-2.2">
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
<!--NHibernate.Dialect.MySQL5Dialect-->
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
<!--NHibernate.Driver.MySqlDataDriver-->
</property>
<property name="connection.connection_string">
Server=SQLEXPRESS;User Id=sa;Password=password;Database=AR200;
</property>
<property name="show_sql">
true
</property>
<mapping assembly="Data" />
</session-factory>
</hibernate-configuration>
<!-- This section contains the log4net configuration settings -->
<log4net debug="true">
<!-- Define some output appenders -->
<appender name="trace" type="log4net.Appender.TraceAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net" >
<param name="File" value="NHibernatelog.txt" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyy.MM.dd" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="DEBUG" />
<appender-ref ref="console" />
</root>
</log4net>
</configuration>
and I do this in test project
Code:
[SetUp]
public void Init()
{
Console.WriteLine("Init() start");
//setup log4net logging
log4net.Config.XmlConfigurator.Configure();
//setup NHibernate
if (_factory == null)
{
Configuration config = new Configuration();
config.Configure();
_factory = config.BuildSessionFactory();
}
_session = _factory.OpenSession();
Console.WriteLine("Init() end");
}