-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to use Log4net with NHibernate?
PostPosted: Tue Apr 03, 2007 2:46 am 
Newbie

Joined: Tue Mar 13, 2007 1:01 am
Posts: 14
I am using Nhibernate and Log4net and I got a problem with them.

I use the following code to write some information in the text file.

string ConfigFile = HttpContext.Current.Server.MapPath(@"ConfigFiles\Log4Net.Config");
XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(ConfigFile));

I just want to write user name, datetime information in my text file but it is written much information about Nhibernate such as mapping info, insertion info,....

How can I write this information into text file :

if (log.IsInfoEnabled)
{
string userName = HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1];
DateTime dt = DateTime.Now;
log.Info("User : " + userName + " Enter application. " + dt.ToString());
}

not too much info about NHibernate.

Could you give me the way to do that ?

Thanks so much

pcphuc.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 4:46 am 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
You need to configure your own logger and appender.

This is part of my config and corresponding code

Code:
  <log4net>
    <appender name="NameOfAppender" type="log4net.Appender.RollingFileAppender">
      (details not relevant)
    </appender>
    <logger name="NameOfLogger">
      <level value="DEBUG"/>
      <appender-ref ref="NameOfAppender"/>
    </logger>
  </log4net>


Code:
LogManager.GetLogger("NameOfLogger").Info("here goes log message");


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 10:31 pm 
Newbie

Joined: Tue Mar 13, 2007 1:01 am
Posts: 14
Thanks for your response.

I put that code in WebConfig and try to write somethings but nothing happen for log writting.

Could you give me the correction for that.

I want to create my own log4net.config file. It is not in Web.config file.

Best Regards,
pcphuc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 10:46 pm 
Newbie

Joined: Tue Mar 13, 2007 1:01 am
Posts: 14
I am sorry, I did some mistakes so it did not work.
Now it works well.

But I got trouble with conversionPattern.

<conversionPattern value="%d [%t] %-5p %c [%x] - %m%n" />

This code I copied from the log4net page but I do not understand much about them.

Could you give me the explanation for that.

Thanks so much.

Best Regards,

pcphuc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 10:53 pm 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
Do some googling and I found this http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 11:18 pm 
Newbie

Joined: Tue Mar 13, 2007 1:01 am
Posts: 14
You helped me much.

Thank you again!

Have a nice day.


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