PDA

View Full Version : log4net troubles


eboix
10-10-2005, 07:55 AM
While I'm quite sure it's not an Spring issue, maybe you'll be able to help me. I'm trying to enable log4net logging in my Spring Managed ASP.NET app.

Here goes the relevant "web.config" sections:


<configSections>
<section name="DatabaseConfiguration" type="System.Configuration.NameValueSectionHandler, System,Version=1.0.3300.0,Culture=neutral,PublicKe yToken=b77a5c561934e089" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net,Version=1.2.0.30714, Culture=neutral,PublicKeyToken=36239442fa0ec68b" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
</sectionGroup>
</configSections>
<DatabaseConfiguration>
<add key="connection.string" value="Data Source=127.0.0.1;Initial Catalog=MAC;User Id=macuser;Password=password;Min Pool Size=5;Max Pool Size=60;Connect Timeout=2;" />
</DatabaseConfiguration>


<log4net>

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net,Versi on=1.2.0.30714, Culture=neutral,PublicKeyToken=36239442fa0ec68b">
<param name="File" value="c:\\inetpub\\app\\mac\\logs\\mac.log" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="20" />
<param name="MaximumFileSize" value="10MB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<filter
type="log4net.Filter.LevelRangeFilter, log4net,
Version=1.2.0.30714, Culture=neutral,
PublicKeyToken=36239442fa0ec68b">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="FATAL" />
</filter>
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>



<root>
<priority value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<logger name="MAC">
<priority value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</logger>

</log4net>

<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="~/Config/mac-context.xml" />
</context>
</spring>



...then in my context xml config file:

<object name="macLog" type="Spring.Objects.Factory.Config.Log4NetFactoryObject , Spring.Core">
<property name="logName"><value>MAC</value></property>
</object>


... that is injected into my objects (ILog property, right ?).

Well... this does not create the logging file.

- I've double checked the permissions. Everything is right.
- I've tried using LogManager.GetLogger directly instead of using Spring's DI, to no avail.
- I've tried using and not using those "PublicKeyTokens", just in case. Nothing.
- I suspect that is related to the config file, if I add "AAA" to the name of the class "log4net.Config.Log4NetConfigurationSectionHandler", no error shows either... I'm puzzled.

BTW, I'm using the lastest build from your web site. Regarding this, how comes that the "release" folder does not contain Spring.Web or Spring.Data while the "debug" folder does ?

Thanks a lot for your time and help,
Regards,
Esteve

eboix
10-10-2005, 08:07 AM
BTW, I'm calling log4net.Config.DOMConfigurator.Configure(); in "Application_Start".

Regards,
Esteve

Rick Evans
10-10-2005, 10:05 AM
Hi

Everything in your configuration looks fine to me.

I suspect that is related to the config file, if I add "AAA" to the name of the class "log4net.Config.Log4NetConfigurationSectionHandler", no error shows either.

Mmm... reaching here, but is your Application_Start method actually being called? Like, can you throw a new FormatException in there and actually verify that the call to the DomConfigurator is actually being invoked?

Another issue (http://forum.springframework.net/viewtopic.php?p=827#827) that lots of folks are having trouble with is the version mismatch between the version of log4net that Spring.NET is compiled against. The linked post should see you right there.

Since you are using Spring.NET's web stuff already, you obviously don't have an issue with pulling stuff from CVS; so, if you take a look in the examples/Spring/SpringAir/src/SpringAir directory off the CVS root, you will see the SpringAir reference application ASP.NET web project. It is very much a work in progress, but at the very least it does have a working logging infrastructure... you could refer to that; not much different apart from the version of log4net and the fact that the latest version uses XmlConfigurator (which is called in the Application_Start method of SpringAir's Global.asax file).

Ciao
Rick

eboix
10-10-2005, 11:35 AM
Hi there,

Thanks Rick for your fast reply.


Mmm... reaching here, but is your Application_Start method actually being called? Like, can you throw a new FormatException in there and actually verify that the call to the DomConfigurator is actually being invoked?


It is called. I've just tested throwing a FormatException.


Another issue (http://forum.springframework.net/viewtopic.php?p=827#827) that lots of folks are having trouble with is the version mismatch between the version of log4net that Spring.NET is compiled against. The linked post should see you right there.


Well I'm actually using the log4net.dll from the Spring distribution... Let me take a look at this post.

Also, I'll take a look ate the SpringAir source.
Thanks a lot again for your help.

Regards,
Esteve

Rick Evans
10-10-2005, 11:46 AM
Hi

The Log4NET version from the Spring.NET distro is 1.2.9.0

The version that you are referencing in the <sections/> section (er) of your config file is 1.2.0.30714 ; to wit...


<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net,Version=1.2.0.30714, Culture=neutral,PublicKeyToken=36239442fa0ec68b" />

Log4NET is configured in the SpringAir reference application using an external file, so I don't know how applicable it is going to be (even after I pointed you there). I used an external file just so that folks could see the embedded config style (as used in the MovieFinder example), and the external file style (as used in SpringAir).

Keep me posted, ciao
Rick

eboix
10-10-2005, 12:10 PM
The Log4NET version from the Spring.NET distro is 1.2.9.0
The version that you are referencing in the <sections/> section (er) of your config file is 1.2.0.30714 ; to wit...


Absolutely right...

Well, I've been browsing the SpringAir app, copying the config settings... It still does not work...

In my Application_Start (which is called), I have:


string configFile = ConfigurationSettings.AppSettings["Log4NetConfigFile"];
//throw new FormatException(Server.MapPath(configFile));
log4net.Config.XmlConfigurator.ConfigureAndWatch(n ew FileInfo("C:/Inetpub/app/macv2/Config/Log4Net.xml"));
log4net.LogManager.GetLogger("MAC").Info("Start");


...no response... no error... no nothing. Even specifying the file "by hand" as in the code, nothing. Even putting a wrong file name, nothing, no error is raised.

I'm quite lost, since I don't have more clues... Surely tomorrow, I'll be "fresher" and I'll find something.

I'll keep you informed.

Best regards, and many thanks again,
Esteve

eboix
10-10-2005, 12:51 PM
Ok. Got it working, at last.

It just happens that the config file was wrong, and, nice as it is, log4net does not throw any exception. Just fails silently.
What you're supposed to do is to add the following to the web.config, so that log4net creates it's own debugging log:


<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="log4netInternalDebugListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="d:\\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>


and


<appSettings>
<add key="log4net.Internal.Debug" value="true" />
</appSettings>


Now you have a log in "d:\log4net.txt" where it puts all it's debug log.

Regards,
Esteve

Rick Evans
10-10-2005, 01:13 PM
Hi

I gotta ask... what was wrong with the config? I'm looking at it again and I don't see it.

Nice tip there, I didn't know that.

Cheers
Rick

eboix
10-10-2005, 02:10 PM
Good question... don't know either.

I've changed so many things...
I added errors to the XML config file on purpose. When I've activated the debug log, log4net complained about those errors. I've corrected them and that's all.
Weird.

Hope that log4net's debug tip will help others with similar problems...

Regards,
Esteve