Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Advantage of ULS Logging

Posted by Paul on July 9, 2013


Logging Information is required for Debugging in Production Deployments. In this article I would compare the usage of SharePoint ULS Logging along with regular Text File Logging.

ULS Logging Here we are using SPDiagnostics class for logging information.

Text Logging Here we are using a TextWriter and writing information to file.

uls log

Advantages of ULS Logging

Following are the advantages of ULS Logging:

1. Log Information can be controlled through Central Administration.

2. Built-in classes for writing log information.

3. Sophisticated Tools available for viewing log entries

While writing ULS Log Information, we need to specify Trace Severity & Event Severity.

image

Through Central Administration, we can control the Trace & Event Severity. Open Configure diagnostic logging from central administration.

image

You can filter the log information based on severity there:

image

Thus, even though our code will contain the Log Writing code, the actual writing only takes place based on the severity level allowed through Central Administration.

This gives the advantage of:

1. Turning On writing to log file through Central Administration when required

2. Turning Off writing to log file when debugging is completed

Sample ULS Logging Code

Following is a test logging code with Trace Severity as High.

SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(“Application”, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, “Message here”);

Following is a test logging code with Trace Severity as Verbose.

SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(“Application”, TraceSeverity. Verbose, EventSeverity.Error), TraceSeverity.Verbose, “Big Message here”);

Verbose severity is used to log too much information, for example writing the internal data structure for debugging purpose.

image

Although Verbose log writing code resides in the Production Deployed Assembly, it will not impact performance when the Central Administration settings is set to exclude Verbose logging.

ULS Log Viewer

You can download the ULS Log Viewer for more convenient viewing of ULS Log information.

image

You can download from:

http://archive.msdn.microsoft.com/ULSViewer

References

http://msdn.microsoft.com/en-us/library/ff512738(v=office.14).aspx

Summary

In this article we have explored the advantages of using ULS Logging in SharePoint. In real world scenarios this provides more convenience & control in the amount of information logged. You can also use ULS Log Viewer for more flexible viewing options.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s