I created an NHibernate project and installed for log4net. But the console does not display log output. My app.config-
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net debug="true">
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{Counter} - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
</configuration>
My hibernate.cfg.xml-
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NhibernateTest">
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
User ID=hr;Password=hr;Data Source=localhost/orcl;
</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="generate_statistics">true</property>
</session-factory>
</hibernate-configuration>
My main program is
using System;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace NhibernateTest
{
class Program
{
static void Main(string[] args)
{
LoadNHibernateCfg();
HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
Queries query = new Queries();
query.Query1();
}
public static void LoadNHibernateCfg()
{
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Program).Assembly);
SchemaExport schemaExport = new SchemaExport(cfg);
schemaExport.SetDelimiter(";");
schemaExport.Execute(true, false,false);
}
}
}
And Queries.csis-
using System;
using System.Collections;
using log4net;
namespace NhibernateTest
{
class Queries
{
public static ILog logger = LogManager.GetLogger("Queries.cs");
public void Query1()
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
logger.Debug("Writing Debug Message before");
IEnumerable res = session.CreateQuery(
"select t.tagId, t.TagName from Tags t where t.id<=10"
).Enumerable();
foreach (object[] tuple in res)
{
Console.WriteLine(tuple[0] + " " + tuple[1] + " ");
}
logger.Debug("Writing Debug Message after");
transaction.Commit();
}
}
}
}
}
Is there something I am missing? Moreover, I need to find out the database query time in this function Query1(). How can I calculate the time using log4net or is there any NHibernate utility for this?
source
share