PDA

View Full Version : Using log4net


dfed
07-28-2005, 04:06 PM
Tell me please how Spring use log4net, where can I see log-file? What does it logging? Or I need to do something to enable it?
And, if it is possible, a simple exemple.
Thanks

Rick Evans
07-28-2005, 04:34 PM
Hi Dmitrij

Spring.NET uses Log4Net for logging. Log4Net is typically configured using a custom configuration section in one's application / web configuration file.

To wit...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>

<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</root>
<logger name="Spring">
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</logger>
</log4net>
</configuration>

This configuration logs to the system console. All of the Spring loggers will only log at the INFO level (i.e. no DEBUG stuff). Everything else (such as your applications logging) will log at the DEBUG level (i.e. everything).

Hope this helps, ciao
Rick

dfed
07-29-2005, 08:27 AM
Thanks Rick!

The logger have to log to the system console all the info messages? Am I right? But I do not see anything..(( I tried to set DEBUG mode in the Spring section... again nothing... Maybe I do not understand what exactly have to log the logger?

Rick Evans
07-29-2005, 08:44 AM
Hi Dmitrij

My apologies. I forgot to add the line of code that actually starts the logging :oops: Add this line of code (preferrably before you do anything else) to start the logging...

XmlConfigurator.Configure();

The MovieFinder example application in the examples directory of the Spring.NET distribution uses log4net, so please do consult that project for a full example.

There are however a bazillion ways to kick off the log4net system (including assembly level attributes, separate configuration files, watched configuration files, etc), so here are some links that you may find useful...

Using log4net (OnDotNet article) (http://www.ondotnet.com/pub/a/dotnet/2003/06/16/log4net.html?page=1)
Quick and Dirty Guide to Configuring Log4Net For Web Applications (http://haacked.com/archive/2005/03/07/2317.aspx)

Ciao
Rick

dfed
07-29-2005, 09:19 AM
XmlConfigurator? - I did't find this class in log4net... there is BasicConfigurator, like in MovieFinder example...
Or maybe I have an old version of log4net?

Rick Evans
07-29-2005, 09:37 AM
Hiya

Mmm... I daresay you are using the version of log4net that ships with the current Spring.NET distribution (version 1.2.0.30714 of Spring.NET RC3). This version of log4net does not contain the XmlConfigurator class. Apologies for that... the 1.0 version of Spring.NET will ship with version 1.2.9.0 of log4net, which does contain the XmlConfigurator class.

You can also use the (equivalent but obsolete) log4net.Config.DOMConfigurator, to wit...

DOMConfigurator.Configure();

Buy you'll get an warning when you compile with the newer version (1.2.9.0)...

'log4net.Config.DOMConfigurator' is obsolete: 'Use XmlConfigurator instead of DOMConfigurator'

Ciao
Rick

dfed
07-29-2005, 10:29 AM
Thanks a lot, Rick!
And the last question, not for this topic, but...
When the 1.0 version of Spring.NET will appear approximately?

Rick Evans
07-29-2005, 10:57 AM
Hiya

The Spring.NET 1.0 release will be released on this coming Monday, August 1st, 2004... definitely, or you get your money back, no questions asked. Satisfaction is guaranteed :)

Just how much satisfaction is debatable, as there is still a lot to do (data access, ASP.NET integration, shiny documentation, etc), but there's a lot of good stuff in the 1.0 release.

Ciao
Rick