Home > DEV, Infrastructure > Sitecore Logging – Log4Net – CastleWindsor

Sitecore Logging – Log4Net – CastleWindsor

As most of you probably already know, Sitecore (until 6.6.0) use an old version of Log4Net in the Sitecore.Logging assembly, you can read more about this issue here

So there are 2 options:

1) Use Sitecore Logging as your logging strategy

2) Use CastleWindsor Logging facilities

In order to implement the second option you have to:

Implement your logging facility:

public class  XXXContainerInstaller : IWindsorInstaller
{
public void Install(Castle.Windsor.IWindsorContainer container,
Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{

//Load your Custom Configuration from a different config “using a more advanced pattern expression

container.AddFacility<Castle.Facilities.Logging.LoggingFacility>(f => f.LogUsing(LoggerImplementation.Log4net).WithConfig(“log4net.xml”));

container.Register(
Component.For<XXXX.ILoggingSetup>()
.Named(“loggingSetup”)
.ImplementedBy<XXXX.Log4net.Log4NetLoggingSetup>()
.LifeStyle.Singleton,

}

}

Prepare your config:

<castle>
<facilities>
<facility id=”logging” type=”Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging” loggingApi=”log4net”/>
</facilities>
<components>
<component id=”loggingSetup” service=”XXX.ILoggingSetup, AssemblyName” type=”XXXX.Log4NetLoggingSetup, Asos.Framework” lifestyle=”AssemblyName”/>
<component id=”loggingContext” service=”XXX.ILoggingContext, AssemblyName” type=”XXXX.Log4NetLoggingContext, AssemblyName” lifestyle=”singleton”/>
</components>
</castle>

The Log4Net Section will still be required and shared between your Castle Logging and SiteCore Logging…

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

<log4net>
<appender name=”eventLogAppender” type=”log4net.Appender.EventLogAppender, log4net” logName=”Application”>
<param name=”LogName” value=”Application”/>
<param name=”ApplicationName” value=”XXXXX”/>
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%appdomain [%thread] %-5level – %message%newline [%properties]%newline %exception”/>
</layout>
</appender>
<root>
<level value=”ERROR”/>
<appender-ref ref=”eventLogAppender”/>
</root>
</log4net>

Be also aware that the SitecoreLogging does not support the latest log4net formatting syntax like %exception

and Sitecore formatting expression prefer the OldLog4Net syntax with all abbreviated letters

<conversionPattern value=”%4t %d{ABSOLUTE} %-5p %m%n” />

More references about this issue can be found:

http://devlicio.us/blogs/casey/archive/2008/06/18/logging-with-castle-windsor-the-logging-facility-and-log4net.aspx

http://damikulik.blogspot.co.uk/2011/05/integrate-sitecorelogging-with-castle.html

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: