Adopting an IoC container has been a software revelation for me. It just keeps on getting better. I just added logging to Suteki Shop simply by doing the following steps (thanks to Sean Chambers for the details)
1. Add a reference to the following Castle Project dlls:
Castle.Facilities.Logging.dll Castle.Services.Logging.Log4netIntegration.dll
2. Configure the LoggingFacility:
<facilities> <facility id="loggingfacility" configfile="log4net.config" loggingapi="log4net" type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging" /> </facilities>
3. Add the log4net config file to the root of the web application:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <log4net> <appender name="RollingFile" type="log4net.Appender.RollingFileAppender"> <file value="sutekishop.log" /> <appendToFile value="true" /> <maximumFileSize value="100KB" /> <maxSizeRollBackups value="2" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%level %thread %logger - %message%newline" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="RollingFile" /> </root> </log4net> </configuration>
And that's all. Isn't that cool, now I can simply add a dependcy for ILogger to any service in my application and log to my heart's content.