Logging useful information, Events and Exception is a core value for all software applications. Imagine that on a real world there are one organization used to log every information within a defined business process for reporting and another one leverage ad-hoc process which allow employees to deal with situations without any defined procedures for reporting to higher management. In the first style, management can monitor and improve its weaknesses by defining their weaknesses and failure points flagged by continuous monitoring and back to the causes of these weaknesses. On the other side the second style, management never improve its weaknesses simply because they never know what are their weaknesses, when one weakness eventually is raised they couldn’t treat it although it might cost organization lot of money and loose customer trust.
Software Applications are similar to organizations no one can know what happen inside it unless there is a rich dashboard to monitor its performance. In a software application system administrators are the top management of the product and the dashboard is the tools that help them to monitor and define weaknesses and failure points.
SharePoint has a very efficient technique to provide system administrator with the required information to monitor the system and provide developers with tracing information to use in solving issues. Developers also can use the SharePoint Logging System in their own customized solution to provide system administrators a greet vision of monitoring and tracing. In this post we will speak on a brief about structure and how to use SharePoint logging System.
SharePoint Logging System mainly target two audiences system administrator and system developers. The information required for both audiences is differ for example system administrator used to use Windows Event Viewer to monitor the performance and identify error messages and send it to the system developers to find solutions for it, on the other hand developer need more information about the error like the username, URL and other contextual information when the error was happened.
SharePoint Logging system use both Event Viewer and Unified Logging System (ULS) trace log for logging messages.
Logging System Structure
SharePoint Logging System is implemented using SharePoint Service Locator System so you can totally change its logging behavior or part of it if you need to do this by implement ILoger, IEventLogLogger or ITraceLogger interfaces and register your new type to SharePoint Service Locator.
SharePoint logging systems use a sample interface as an entry point called ILoger. The ILogger interface is designed to accommodate most logging scenarios and to help developers target their messages to either system administrators or developers. It does this by defining two key methods: LogToOperations and TraceToDeveloper.
The logic behind these two methods is that LogToOperations targets both system administrators and developers and is used to log operational information only as it takes a string message as one of its parameters, on the other hand TraceToDeveloper targets system developers and is used to log exceptions that happened with contextual information and this clear as it takes exception object as one of its parameters.
To summaries main SharePoint logging system functionality, it contains two parts which are:
- Logging operational inforamtion targets system administrators
- Logging tracing information targets system developers
SharePoint Default Logging System implementation
As we mentioned on the previous section SharePoint logging system use SharePoint Service Locator system so anyone can change its behavior programmatically for example you can make it log to database or send emails in some cases
Below figure display default implementation of the SharePoint logging system
Default SharePoint logging interface implementation is used by SharePointLoger class which in turn call two interfaces ITraceLogger and IEventLogLogger. The implementation of ITraceLogger interface is implemented by the TraceLogger class that implemented to provide a contextual information for the logged exceptions like current user and current URL. Implementation of IEventLogLogger is handled by EventLogLogger class which log the information in the event viewer plus log it to (ULS) system
ITraceLogger and IEventLogLogger also called using SharePoint Service Locator so you can change one of these parts only by implement its interface and register you new type to SharePoint Service Locator
- Logging useful information, Events and Exception is a core value for all software applications
- SharePoint Logging System targets both audiences system administrators and system developers
- SharePoint Logging System logs operation information for system administrators on Windows Event Viewer plus (ULS) system
- SharePoint Logging System logs tracing information for system developers on Unified Logging System (ULS)
- SharePoint developers can programmatically change all default SharePoint Logging System behavior on the following levels using SharePoint Service Locator System
- ILoger interface
- ITraceLogger interface
- IEventLogLogger interface
- SharePoint developers can use SharePoint Service Locator to add logging for their custom solutions that used on the running context