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.  [ 2 posts ] 
Author Message
 Post subject: Configure NHibernate Log seperately to applications log
PostPosted: Wed Sep 02, 2009 5:07 am 
Newbie

Joined: Thu Oct 30, 2008 8:49 am
Posts: 11
Location: Goslar / Germany
Hi devmates,

of course i tried the search-field first, but couldnt find something pointing my problem.

I am trying to configure the nhibernate logger seperately to my applications log, as described in the subject ;).

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
  </configSections>

  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="Logs\Framework.log" />
      <appendToFile value="true" />
      <maximumFileSize value="30MB"/>
      <maxSizeRollBackups value="5"/>
      <rollingStyle value="Composite" />
      <datePattern value="-yyyy-MM-dd.lo\g" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %-5level %logger - %message%newline" />
      </layout>
    </appender>

    <root>
      <level value="WARN" />
      <appender-ref ref="RollingLogFileAppender" />
    </root>
  </log4net>
</configuration>


So, if i configure the log value to any value, the nhibernate logger logs everything it cans. Is there any way to disable the logs from nhibernate and keep my own log´s in my application alive? Or at least i would like to say:

Hey, NHibernate´s Logger, please just log your Warnings or Errors and Hey Application´s Logger, you can log on INFO.

Hope you understand my problem.

best regards
ap


Top
 Profile  
 
 Post subject: Re: Configure NHibernate Log seperately to applications log
PostPosted: Wed Sep 02, 2009 11:33 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Add this:

Code:
    <logger name="NHibernate">
      <level value="WARN" />
    </logger>

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

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


For application logging you then can use:

LogManager.GetLogger( "MyApp" );

Or if you want it to based on the namespaces (gives you much more flexibility for configuring logging for debugging):

Code:
     private static readonly ILog log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType );

    <logger name="some namespace from my app">
      <level value="DEBUG" />
    </logger>
[/code]

For more info I recommend the log4net documentation.

_________________
--Wolfgang


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