-->
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: log4net config
PostPosted: Fri Jul 22, 2005 4:08 pm 
hi.

I'm using nhibernate in an asp.net project, and want to know how to config my log4net. I created a file called App.config, but it didn't have any effect. I also tried to put it in my Web.config file, but didn't work either.
Does someone know how to configure it?

thanks.


Top
  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 6:36 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
First of all in ASP.NET projects you can use ONLY the web.config file for configuring your web app.

The web.config file I currently use looks like this:
Code:
<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.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="Server=(local);initial catalog=DataBaseName;User ID=username;Password=password;Min Pool Size=2"/>
   </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] &lt;%X{auth}&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] &lt;%X{auth}&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] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>

      <!-- Setup the root category, add the appenders and set the default priority -->

      <root>
         <priority value="ERROR" />
         <appender-ref ref="rollingFile" />
      </root>

      <logger name="NHibernate.Impl.BatcherImpl">
         <level value="ERROR" />
      </logger>

   </log4net>
<!-- from here, the standard web.config content-->
</configuration>


So basically you have to add the <configSections> tag which declare the handlers for the <log4net> and <nhibernate> tags, then you put the log4net and nhibernate tags. Do a search for log4net you will find plenty of docs about how to set it up. Still you have to clarify what do you mean by "log4net is not working"? You havn't got any entries in the logs? You have to keeep in mind that there are issues with using a file appender in ASP.NET apps, by default the ASP.NET worker process does not have enough credentials to write on your disk. Usually you have to grant to the ASPNET user the right to write on the directory where your web app resides. Anyway you should get log entries in your VS.NET console if you have declared a console appender. Again I advise you to do a google for log4net and ASP.NET. Here some links I've found useful:

http://tom.gilki.org/programming/net/120604/
http://weblogs.asp.net/dr.netjes/archive/2005/02/16/374780.aspx
http://haacked.com/archive/2005/03/07/2317.aspx

Cheers,
Radu


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.