Sitecore 8 Log4net

The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets

Sitecore makes use of the log4net library to record the any errors.

There are different types of appenders but I won’t go into details. You can visit the Apache Site for the list of appenders. Today’s post concerns about how to debug the log4net to see why the errors are not being logged into the database.

As from Sitecore 8.x, the log4net has moved into the Sitecore.config. So, if you are upgrading from a lower instance, remember to change the log4net configurations from the web.config to the Sitecore.config. But the recommendation is to patch the log4net into a new config file.

Patch File

Open a notepad and save the text as z.Logging.config. Once this is done, write down your custom appender. Below is a snippet of my appender which logs the error into a SQL Server Database:

In order to be able to debug the log4net in Sitecore, first, open the web.config found in the Website folder. Under the “” add the following statement:

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

Then, add the following at the end of the web.config:

This will create a textfile with the name log4net.txt into the ‘C:’ drive.

One keynote, if you specify the connection string in the Log4net directly, you need to escape the ‘\’ characters. I had been trying to get my log4net working with a database for hours on our Staging Environment while it was working properly on my local instance. Suppose you are using the following connection string in the Log4net tag

<param name="ConnectionString" value="user id=[userId];password=[password];Data Source=ServerName\CD_CUSTOM;Database=Sitecore.Logging" />

You need to escape the

Data Source=ServerName\CD_CUSTOM;Database

to

Data Source=ServerName\\CD_CUSTOM;Database
Advertisements

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