-->
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.  [ 10 posts ] 
Author Message
 Post subject: NHibernate and log4net - where's my logfile?
PostPosted: Tue Jan 24, 2006 2:58 pm 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
Hi!

I am soooo frustrated with the log4net - everibody seems to get it working like a charm, but not me.
Here's what I did:
* I created proper config for my WinForm app
http://wiki.nhibernate.org/display/NH/C ... et+Logging
, only enabled the rollingFile logging
* added reference to log4net

re-compiled my app, ran it, but where is my log.txt ?
I can see log messages in debug window, but lo log file. By the way, I had to use BasicConfigurator.Configure(); ... because [assembly: log4net.Config.XmlConfigurator()] simply did not work!

so can someone put here actually working tutorial, I am kinda tired of looking from the rtfm-s.


Top
 Profile  
 
 Post subject: Re: NHibernate and log4net - where's my logfile?
PostPosted: Wed Jan 25, 2006 1:25 am 
Newbie

Joined: Tue Jan 24, 2006 10:02 pm
Posts: 12
With me, it is in the same directory as the .exe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 3:58 am 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
Yes, I also supposed that it should be in the same directory ... but sadly, it isnt. I only got working output to console, even though I defined that output should be rollingFile ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 5:12 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Post your configuration here please.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 6:52 am 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
Here's the app.config

Code:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>

   <nhibernate>
   <add key="hibernate.show_sql" value="false"/>
   <add key="hibernate.use_reflection_optimizer" value="false"/>
   <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="..."/>
   
   </nhibernate>
   
   <!-- This section contains the log4net configuration settings -->
   <log4net debug="false">

      <!-- 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 [%x] &amp;lt;%P{user}&amp;gt; - %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 [%x] &amp;lt;%P{user}&amp;gt; - %m%n" />
         </layout>
      </appender> -->

      <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net" >
         
         <param name="File" value="log.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 [%x] &amp;lt;%X{user}&amp;gt; - %m%n" />
         </layout>
      </appender>

      <!-- Setup the root category, add the appenders and set the default priority -->
      
      <root>
         <priority value="INFO" />
         <appender-ref ref="rollingFile" />
      </root>
   </log4net>
   
</configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 7:24 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Could it be a permission issue? Try setting debug="true" in <log4net> element.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 8:32 am 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
It's definitely not a permission issue. I checked the debug log, and it seems everything is OK, no errors that file cannot be created etc ... so its a mystery.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 8:51 am 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
Found solution!

RTFM is incorrect, here is how I solved it:

* add reference to log4net
* configure app.config as see in http://wiki.nhibernate.org/display/NH/C ... et+Logging
* in the class constructor, add following line:
Code:
using System;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Expression;
using System.Configuration;
using System.Collections;
// Import log4net classes.
using log4net;
using log4net.Config;

namespace Common.Data
{

   public class DataFactory:IDisposable {
                public DataFactory() {
                        // configure log4net
                        log4net.Config.XmlConfigurator.Configure();
                        // do the rest of initialization
                }
        }
}


So BasicConfigurator.Configure(); does not work. It's sad because I had to waste 1 working day just to get the damn thing working.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 9:37 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Right... I have noticed the BasicConfigurator bit only now. BasicConfigurator does really basic configuration and this means it configures all logging to go to the console. It's strange that the assembly attribute didn't work for you though.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 5:22 am 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
Assembly attribute did not work for me, I really don't know why. Tried several times and several configurations, but nothing. Still have to use log4net.Config.XmlConfigurator.Configure(); in ctor.
I also got some init errors when debugging the code, log4net asked to change the following section:
Code:
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905" />

And in the Reference, I had to make sure that CopyLocal attribute for log4net was set to true.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.