-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Log4Net
PostPosted: Mon Mar 20, 2006 7:53 pm 
Newbie

Joined: Mon Jan 09, 2006 12:27 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: sql server express 2005

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt: INFO


Hi, I configured NHibernate, but I'm not able to get any log file out of it. I gave full control to the ASPNET process to the folder. The same configuration works in another project, so I'm not sure what's going on. Here is the configuration in web.config

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.1.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>

<log4net>
<appender name="Console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<!-- Pattern to output the caller's file name and line number -->
<conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
</layout>
</appender>
<appender name="AspNetTraceAppender" type="log4net.Appender.AspNetTraceAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="NHibernateSample.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="AspNetTraceAppender" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
</log4net>
<appSettings>
<add key="HBM_ASSEMBLY" value="NHibernateSample.Core"/>
</appSettings>
<nhibernate>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.connection.connection_string"
value="Data Source=VENICE\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True" />
<add key="hibernate.connection.isolation" value="ReadCommitted" />
<add key="hibernate.default_schema" value="Northwind.dbo" />
<add key="hibernate.show_sql" value="true" />
</nhibernate>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 9:42 pm 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
Try adding a logger def within the <log4net> section in your config which says what appender will be invoked within the NHibernate namespace, e.g.


Code:
    <logger name="NHibernate" additivity="false">
      <level value="DEBUG" />
      <appender-ref ref="RollingFile"/>
    </logger>


Other than than, have you tried setting the logging level lower to DEBUG?

FWIW, I am using NH in an ASP.Net web service and am getting log entries written out OK.

HTH,
Dean.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 9:55 pm 
Newbie

Joined: Mon Jan 09, 2006 12:27 am
Posts: 8
Yeah I tried that and still didnt' work.

I simply want to see the deafult sql outputted by NHibernate and it worked in another project but not this one. I just copy and pasted the info.

BTW, I didn't use any debug methods etc in my own code yet. Just want to see teh default message.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 10:05 pm 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
I'm not sure why it's not working for you. When I put the following in my web.config file, I get NHibernate INFO statements in the NHibLog.txt file.

Code:
<log4net>
    <appender name="NHFile" type="log4net.Appender.RollingFileAppender,log4net" >
      <param name="File" value="NHibLog.txt" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
       <maxSizeRollBackups value="10" />
       <maximumFileSize value="100KB" />
      <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 [%x] - %m%n" />
      </layout>
    </appender>

    <root>
       <level value="INFO"/>
       <appender-ref ref="NHFile" />
    </root>
  </log4net>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 10:28 pm 
Newbie

Joined: Mon Jan 09, 2006 12:27 am
Posts: 8
Hi DeanOC, thanks for the reply. I just got it resovled according to this
http://www.hibernate.org/364.html

Other than copying the above configuration, I also had to put this in my global.asax.

void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
log4net.Config.XmlConfigurator.Configure();
}

did you have to do that? If not, where did you instantiated the logging?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 10:41 pm 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
Well done. I had gforgotten all about XmlConfigurator as we have a wrapper class for the log4net logger (out of sight out of mind).

Its constructor calls
Code:
XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));

Which is essentially what you are doing. ConfigureAndWatch is not really needed for a web app , but our logger class is also used in our client apps and ConfigureAndWatch allows the apps to dynamically detect changes to logging parameters.

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 10:44 pm 
Newbie

Joined: Mon Jan 09, 2006 12:27 am
Posts: 8
Thanks again!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.