-->
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.  [ 8 posts ] 
Author Message
 Post subject: nHibernate and NLog?
PostPosted: Thu Jan 17, 2008 11:51 am 
Newbie

Joined: Thu Jan 17, 2008 11:45 am
Posts: 9
Location: VA
I was recently placed on a project that has decided to use NLog for their logging library. However I'm pushing for nHibernate for our ORM but I can't seem to find if I can use NLog instead of log4net with nHibernate. Does anyone know if I can substitute NLog for log4net.

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 19, 2008 12:12 pm 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Hi,

You can't. NHibernate is tied to log4net.

Best regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 9:54 am 
Newbie

Joined: Thu Jan 17, 2008 11:45 am
Posts: 9
Location: VA
Thank you darioquintana.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 4:46 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
It might be worth creating a patch for nhibernate that allows you to specify a logging provider in the hibernate configuration. For kicks, I created a project around structuremap that allowed one to dynamically swap out logging frameworks at runtime... that's overkill for this, but the net result is that I learned it's rather trivial to create a common interface and implementation as a facade over nlog and log4net.

I'll look at it if I have time. I don't know enough about a lot of nhibernate to know how much work it would be, but it might be useful for others too....

or, you could argue that nhibernate is a separate, isolated subsystem and, as such, should have its own logging area anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 12:02 am 
Newbie

Joined: Wed Feb 21, 2007 10:45 am
Posts: 2
Spring.net uses http://netcommon.sourceforge.net/. I've seen this brought up on the NHibernate dev list before and it was shot down as yet another abstraction. Maybe thoughts have changed since then.

-Shane


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 12:47 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Hi,

For example, EntityName is quite closer to be fully implemented. And there is a lot of features that need to be finish (without counting the need of documentation of these features)

CommonLogging could be interesting for a future, now it works and do it fine.

Those are my thoughts, by the way, you can send a email to the dev-list for hear what they say.

Best regards

_________________
Dario Quintana


Top
 Profile  
 
 Post subject: Build a bridge
PostPosted: Mon Feb 04, 2008 2:39 am 
Newbie

Joined: Thu Jul 26, 2007 8:17 am
Posts: 3
We had a very similar issue. We use NLog as our logging system and did not want to have to configure and maintain two different logging configurations.

Our solution was to build a bridging class and to configure it as the root appender for log4net.

For example:
Code:
/// <summary>uses nlog loggers to output the log messages from log4net</summary>
public class Log4NetToNLogAdaptor : IAppender
{
    public void DoAppend(LoggingEvent loggingEvent)
    {
            Logger log = NLog.LogManager.GetLogger(loggingEvent.LoggerName);
            Exception exception = loggingEvent.ExceptionObject;
            string message = loggingEvent.RenderedMessage;

            if( loggingEvent.Level >= Level.Critical )
            {
                if (exception != null)
                    log.FatalException(message, exception);
                else
                    log.Fatal(message);
            }
            else if (loggingEvent.Level >= Level.Error)
            {
                 ....
            }
            ...
    }
}


and to configure the bridge (eg: in Application_Start):
Code:
BasicConfigurator.Configure(new Log4NetToNLogAdaptor());


You can then configure log4net loggers in your nlog configuration file in the same way you would configure nlog loggers:
Code:
<logger name="NHibernate.SQL" minlevel="Debug" writeTo="trace,file" final="true"/>


regards,
Paul.


Top
 Profile  
 
 Post subject: Re: Build a bridge
PostPosted: Fri May 20, 2011 3:13 pm 
Newbie

Joined: Tue Aug 28, 2007 1:01 pm
Posts: 8
Location: Indonesia
fatal2 wrote:
We had a very similar issue. We use NLog as our logging system and did not want to have to configure and maintain two different logging configurations.

Our solution was to build a bridging class and to configure it as the root appender for log4net.


Wow, it looks so simple! I never thought it could be like that.

Thanks for the sharing the solution, Paul.

_________________
Regards,

Maximilian Haru Raditya


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