PDA

View Full Version : How to enable Spring logging?


rolandz
02-21-2007, 08:09 AM
Hi,

I would like to enable the spring (internal) logging via log4net. What should I set? I've seen the common logging section in the configuration of application. But how to properly set this up. My preferred solution is to have log4net.config file.

I already am using log4net (at least initializing it for NHibernate):


<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">

<object id="Log4NetInitializer"
type="Spring.Objects.Factory.Config.MethodInvokingFactor yObject, Spring.Core">
<property name="TargetType" value="log4net.Config.XmlConfigurator, log4net" />
<property name="TargetMethod" value="Configure" />
<property name="Arguments">
<list>
<value type="System.IO.Stream">~/Config/Log4Net.config</value>
</list>
</property>
</object>

<object id="loggingAroundAdvise"
type="Spring.Aspects.LoggingAroundAdvice, CMS"
depends-on="Log4NetInitializer">
<property name="Level" value="Warn" />
</object>
</objects>


I have a log4net.config there as well. But I have a strong feeling that there is better way... Especially because the spring doesn't log - it prooves that it is wrong way rather...

Erich Eichinger
02-21-2007, 11:03 AM
Hi,

to enable spring logging, you need to configure Common.Logging. To do this, add the following to your app.config:


<configuration>
<configSections>

<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>

</configSections>

<common>
<logging>
<factoryAdapter
type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter , Common.Logging.Log4Net129">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/log4net.config" />
</factoryAdapter>
</logging>
</common>
</configuration>


This will (a) initialize log4net and (b) configure Common.Logging to use log4net for output. You can safely remove your "log4netInitializer"-objectdefinition.

Depending on the log4net version (1.2.9 / 1.2.10) you need to choose between Common.Logging.Log4Net and Common.Logging.Log4Net assembly

The reference documentation contains some more information on Common.Logging (http://www.springframework.net/doc-latest/reference/html/ch13.html)

hope this helps,
Erich