PDA

View Full Version : How to configure Log4net?


liming
03-19-2007, 05:03 AM
Hi,

I'm trying out a very simple example using Spring.NET/NHibernate/ASP.NET and I'm getting "object referene not set to an instance of an object" when it hits HibernateTemplate.Save()

I'm trying to load the internal Spring log, but it's not showing up anywhere in my log file.

This is what I did

Web.config
--------------

<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
<section name="databaseSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler , Spring.Core"/>
</sectionGroup>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
</configSections>
<spring>
<parsers>
<parser namespace="http://www.springframework.net/database" type="Spring.Data.DatabaseConfigParser, Spring.Data" schemaLocation="assembly://Spring.Data/Spring.Data/spring-database.xsd"/>
</parsers>
<context>
<resource uri="Dao.xml"/>
</context>
</spring>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter , Common.Logging.Log4Net">
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
<!-- otherwise BasicConfigurer.Configure is used -->
<!-- log4net configuration file is specified with key configFile-->
<arg key="configType" value="EXTERNAL"/>
</factoryAdapter>
</logging>
</common>
<databaseSettings>
<add key="db.datasource" value="192.168.2.3"/>
<add key="db.user" value="sa"/>
<add key="db.password" value="sa"/>
<add key="db.database" value="JumptreeForum"/>
</databaseSettings>
...
<log4net>
<appender name="PMRollingFile" type="log4net.Appender.RollingFileAppender">
<!-- Please make shure the ..\\Logs directory exists! -->
<param name="File" value="Fourm.log"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="300KB"/>
<param name="RollingStyle" value="Size"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="PMRollingFile"/>
</root>
<logger name="Spring">
<level value="INFO"/>
</logger>
<logger name="Spring.Data">
<level value="INFO"/>
</logger>
</log4net>
</configuration>

What am I doing wrong? Any suggestion is appreicate it.

Thanks.

liming
03-19-2007, 05:09 AM
and oh yeah,

I referened these libraries

antlr.runtime.dll
Iesi.Collections.dll
Common.Logging,
Commong.Logging.log4Net129.dll and
Log4net.dll
Spring.Aop.dll
Spring.Core.dll
Spring.Data.dll
Spring.Data.NHibernate12.dll

Thanks again.

Bruno Baia
03-19-2007, 10:10 AM
Hi,

Common.Logging.Log4Net129 is intended to be use with log4net 1.2.9
Common.Logging.Log4Net is intended to be use with log4net 1.2.10 and future releases.
( The need for two is because log4net changed the key they use to sign their assemblies from 1.2.9 to 1.2.10. )

So if you are using NHibernate 1.2, you should use Common.Logging.Log4Net.dll because NHibernate 1.2 uses log4net 1.2.10


<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter , Common.Logging.Log4Net">
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
<!-- otherwise BasicConfigurer.Configure is used -->
<!-- log4net configuration file is specified with key configFile-->
<arg key="configType" value="EXTERNAL"/>
</factoryAdapter>

Use INLINE instead if you want to use Log4Net configuration from the file.

The factory adapter type you reference is in Common.Logging.Log4Net.dll assembly, and should be in the bin directory to work.


HTH,
Bruno

boriska
03-27-2007, 09:07 AM
Hello,

I have a similar issue: in my older test project I successfully used Common.Logging.Log4Net129. Now I'm trying Hibernate12, so I changed
web.config, but nothing will happen. The Application injects the default Common.Logging.Simple.NoOpLogger that does nothing...

All dll's were in bin-folder and I also added references to log4net, Common.Logging, Common.Logging.Log4Net without any success.

Could anybody give a tip?

Thanks,
Boris

You can see some extract’s from my Web.config file below:

<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler , Spring.Core"/>
</sectionGroup>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>

<section name="databaseSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>


<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter , Common.Logging.Log4Net">
<arg key="configType" value="FILE-WATCH"/>
<arg key="configFile" value="~/Log4NET.xml"/>
</factoryAdapter>
</logging>
</common>

<appSettings>
<add key="Log4NetConfigFile" value="~/Log4NET.xml"/>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.SessionFactoryObjectName" value="sessionFactory"/>

</appSettings>

<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule, Spring.Data.NHibernate12"/>
</httpModules>

boriska
03-30-2007, 03:47 PM
Hello,

today I replaced the dll's (the codebase from 2007 03 19) with some newer (
Spring.Data.NHibernate12-20070329-1141, Spring.Data.NHibernate-20070330-0103, Spring.NET-20070329-2215 ) and my logging issue has gone.
The logging works for me now.

I think that the Castle and the log4net dll's are older than for codebase 20070319.

Regards,
Boris