Sitecore Client Logging with JSNLog In Sitecore 8.1

With Sitecore 8.1, support has been added to log client side events. The new logging framework is built upon the standard Sitecore logging framework (which uses Log4net), allowing client side events to be logged back to the data/log folder on the delivery server.

Under the hood, Sitecore client logging uses JSNLog which has been wrapped to allow Sitecore to configure it via a patch and to make use of the existing Log4net logging.

Configuration

All configuration for client logging is contained within Sitecore.JSNLog.config within App_Data/Include.

jsnlog element

Enabled – Allows Client logging to be enabled. Beware disabling this option as the Sitecore CMS uses client logging for its diagnostics. You may need this option on if you need to raise support tickets.

productionLibraryPath – Allows you to change the path at which the jsnlog JavaScript is located. This is useful when the Sitecore directory isn’t deployed on a delivery server.

serverSideMessageFormat – Here you can specify the format of the error message that is stored within the log. Above in the comments in the config file are a list of all the varibles. These can be seen below.

ajaxAppender

This is the appender thats used to write the errors to the Sitecore data log folder. Here we can specify the error level.

level – Here you can specify what level of logging is used (DEBUG|ERROR|INFO)

Using Client Logging In Your Website

This is simple, logging will work if the JSNLog JavaScript has been rendering into the head of your HTML, this is done via a Sitecore helper. The helper within the Diagnostics namespace that renders out the JavaScript pulling the required varibles into the JavaScript.

Logging is now enabled, Sitecore will capture all unhandled JavaScript errors and log them in the log folder on the server. You can also write to the log via the JSNLog API “JL()” as below.

By default when using client logging you will see a JSON object being displayed in your browser’s console every time you write to the log. You can see this below

Client JavaScript Error Logging
Client JavaScript Error Logging

 

This functionality can be switched off, so logs are written but the log isn’t displayed in the console window.

Within the Sitecore.JSNLog.config, there is an appender for the console called – consoleAppender. This is enabled by the logger appender element that accepts a comma seperate list of appenders. Removing the consoleAppender from this list disabled the console appender.

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