Overview

Sponge's Logging Component is based on NLog - we built a centralized way of managing NLog configs in SharePoint that can be used with server- and client-side API.

Sponge Targets

Usage

alt text

alt text

That's it from the SharePoint side. Have a look at the server- and client-side API on how to get the configs from Sponge!

Online - Offline Mode

Sponge's logging component has different ways of loading the logging configuration.

Server Side

In order to use the server side API reference Sponge.dll and NLog.ddl lib and add using Sponge.Logging; to your usings.

Online
public void LogMsgServerSideOnline()
{
        //gets the log info from central admin
	var log = LogManager.GetOnline("Sponge Log Viewer");
	
        //gets the log info from site collection
        var log = LogManager.GetOnline("http://demo", "Sponge Log Viewer");

	//this will log a test message to the target that was associated with 'Sponge Log Viewer' in SP
	log.Debug("This is {0} debug msg", "my");
}
Offline
public void LogMsgServerSideOffline()
{
	//path to the config file; this can be local or a network share
	var path = "../../log.config";
	
	var name = "My Logger";
	
	//this will initalize the logger with name 'My Logger'
	//if you do not specify name it will use the default name 'Sponge.Logging.Logger'
	var log = LogManager.GetOffline(path, name);

	log.Debug("This is {0} debug msg", "my");
}

Client Side

In order to use the server side API reference Sponge.Client.dll and NLog.ddl from lib and add using Sponge.Client.Logging; to your usings.

Online
public void LogMsgClientSideOnline()
{
        //url to the Site Collection
        var spongeUrl = "http://demo";

        //name of the app in sharepoint
        var app = "Sponge Log Viewer";

        //whether the ClientLogManager should retrieve the log config from central admin (true) or from the relative Sponge Admin Page (false)
        //relative means --> "http://demo/Sponge" --> Sponge Logging & Configuration Component Feature has to be enabled in this Site Collection
        var central = false;

        //create the logger instance
	var log = ClientLogManager.GetOnline(spongeUrl, app, central);
	
	//this will log a test message to the target that was associated with 'Sponge Log Viewer' in SP
	log.Debug("This is {0} debug msg", "my");
}
Offline
public void LogMsgClientSideOffline()
{
	//path to the config file; this can be local or a network share
	var path = "../../log.config";
	
	var name = "My Logger";
	
	//this will initalize the logger with name 'My Logger'
	//if you do not specify name it will use the default name 'Sponge.Logging.Logger'
	var log = ClientLogManager.GetOffline(path, name);

	log.Debug("This is {0} debug msg", "my");
}
JavaScript

The Sponge JavaScript API allows you to use the logging component of Sponge in JavaScript. If you want to use the js API in a page where the Sponge Logging & Configuration Component Feature is not enabled (it will automatically inject sponge.js in every page), simply reference the _layouts/Sponge/scripts/sponge.js file.

The js API also supports Central & Relative installation, just like the rest of the API does.

Note: To make the js API work, you have to configure the Sponge Logging Web Service application in your (central/relative) admin site. It is automatically added on installation and will log to the ULS log. If that is fine with you, leave it like this, otherwise configure a different target. However, do not delete this application, otherwise the js api will fail.

try {
alllert("will fail");
}
catch(err) {
    //makes the call to the central admin installation
    sponge.logging.log("Error", err.message);

    //makes the call to the site collection http://demo
    sponge.logging.log("Error", err.message, "http://demo");
}

Supported API

Server Side

Client Side