-->
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: How do i actice Logging?
PostPosted: Wed Mar 26, 2008 11:48 am 
Newbie

Joined: Tue Mar 25, 2008 11:48 am
Posts: 12
Ola!

I want to activate Logging. My Project ist a Windows Applikation and i use the newest NHibernate Version.

Can Somebody help me? I see that i must use log4net, but i don't understand how to config this tool with a app.config file.....

Many Tnx, teLLy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 12:10 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have look on these posts http://forum.hibernate.org/viewtopic.php?t=984813&highlight=

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 12:56 pm 
Newbie

Joined: Tue Mar 25, 2008 11:48 am
Posts: 12
i Tried it, but it will not work: I try to explain my Steps:

First create new file "app.config"
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>

  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <!--<property name="connection.connection_string">Server=(local);Database=studio;Uid=studio;Pwd=;</property>-->
      <property name="show_sql">false</property>
      <mapping assembly="Studio.Database.NHibernate"/>

    </session-factory>


  </hibernate-configuration>

  <log4net debug="false">

    <appender name="TraceAppender" type="log4net.Appender.TraceAppender, log4net">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%-5level %M - %message%newline" />
      </layout>

    </appender>


    <root>
      <level value="OFF" />
      <appender-ref ref="TraceAppender"/>
    </root>

    <logger name="NHibernate">
      <level value="OFF"/>
    </logger>


    <logger name="Logger">
      <level value="OFF"/>
      <appender-ref ref="TraceAppender" />
    </logger>

    <logger name="NHibernate.Loader.Entity.AbstractEntityLoader">
      <level value="OFF"/>
      <appender-ref ref="TraceAppender"/>
    </logger>

  </log4net>

</configuration>


Than i set "Build Action" = Embedded Ressource

Than i edit my Programm.cs
Code:
[STAThread]
        static void Main()
        {
           
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            log4net.Config.XmlConfigurator.Configure();
           
            Application.Run(new Form1());
        }


Than i called the Configuration File:
Code:
private Configuration _Configuration = new Configuration().Configure(); 


But the Logging will not work! What shut i change? And where can i generally see the logging? i prefared it, if log4net will create a txt.file....

teLLy


Top
 Profile  
 
 Post subject: How do i actice Logging?
PostPosted: Wed Mar 26, 2008 5:18 pm 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi teLLy,

Here's an example log4net configuration I posted previously that writes to a file:
Code:
<configuration>

    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
        ...
    </configSections>

    <log4net>
        <appender name="MyNhLog" type="log4net.Appender.RollingFileAppender">
            <param name="File" value="c:\MyNhLog.log"/>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%d level %message%newline" />
            </layout>
        </appender>
        <logger name="NHibernate">
            <level value="INFO" />
            <appender-ref ref="MyNhLog"/>
        </logger>
    </log4net>
    ...
</configuration>


Originally posted here:
http://forum.hibernate.org/viewtopic.php?p=2375439

This writes to a file at c:\MyNhLog.log. Is that what you were after?

Regards,
Richard

P.S., just double-checking; the app.config is not an embedded resource - just your .hbm.xml files.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 3:18 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You have to change the level values to something different then OFF: INFO, WARNING, ERROR, DEBUG.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 7:03 am 
Newbie

Joined: Tue Mar 25, 2008 11:48 am
Posts: 12
Also Tnx for the Help here !!

Hmm, i changed the app.config file to:

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>

  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <!--<property name="connection.connection_string">Server=(local);Database=studio;Uid=studio;Pwd=;</property>-->
      <property name="show_sql">false</property>
      <mapping assembly="Studio.Database.NHibernate"/>

    </session-factory>


  </hibernate-configuration>

  <log4net debug="false">

    <appender name="TraceAppender" type="log4net.Appender.TraceAppender, log4net">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%-5level %M - %message%newline" />
      </layout>

    </appender>
   
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
      <file value="example.log" />
      <appendToFile value="true" />
      <maximumFileSize value="100KB" />
      <maxSizeRollBackups value="2" />

      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%level %thread %logger - %message%newline" />
      </layout>
    </appender>


    <root>
      <level value="DEBUG" />
      <appender-ref ref="TraceAppender"/>
    </root>

    <logger name="NHibernate">
      <level value="DEBUG"/>
    </logger>


    <logger name="Logger">
      <level value="DEBUG"/>
      <appender-ref ref="TraceAppender" />
    </logger>

    <logger name="NHibernate.Loader.Entity.AbstractEntityLoader">
      <level value="DEBUG"/>
      <appender-ref ref="TraceAppender"/>
    </logger>

  </log4net>

</configuration>


But no while will be created...what i have to change???

teLLy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 7:16 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi Telly,

If you want to use the appender with name 'RollingFile', then you need to add an appender-ref to it.

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


Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 7:25 am 
Newbie

Joined: Tue Mar 25, 2008 11:48 am
Posts: 12
I try this a few minits ago but it will not work. Log4net doesnt create a file.

Any suggestions?

EDIT:

How to activate Logging in my applikation? I only add

log4net.Config.XmlConfigurator.Configure();

to the Programm, but i assume this Method doesnt find the App.config. Should i add call another Method or set a special Property eg?

teLLy


Top
 Profile  
 
 Post subject: How do i actice Logging?
PostPosted: Thu Mar 27, 2008 7:42 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi Telly,

The configuration of your log4net RollingFileAppender is different to the example I gave earlier.

Can you try replacing your entire log4net section with just:
Code:
<log4net>
    <appender name="MyNhLog" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="MyNhLog.log"/>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%d level %message%newline" />
        </layout>
    </appender>

    <logger name="NHibernate">
        <level value="INFO" />
        <appender-ref ref="MyNhLog"/>
    </logger>
</log4net>


Regards,
Richard

P.S., the .config file should be named according to your .exe ... so your config file should be named App.exe.config if your application is App.exe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 8:16 am 
Newbie

Joined: Tue Mar 25, 2008 11:48 am
Posts: 12
Ola!

I get it.

I had to set the App.config
Build Action = None
Copy to Output diretory = Do not copy


Tnx for all your Support!

teLLy


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.