You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$10
For Premium members:
In this article we can explore a debugging scenario using the SPDiagnosticsService class and the SharePoint 2010 Logging Severity Levels.
In this article we can explore a debugging scenario using the SPDiagnosticsService class and the SharePoint 2010 Logging Severity Levels.ScenarioYour customer reported that in the middle of an operation the SharePoint site is not responding. You need to determine what the underlying issue is.SolutionSince the issue is happening in the production environment you can use the Diagnostics capabilities of SharePoint 2010.The following are the activities involved in the analysis:
Here we are going to perform the first 3 activities. SPDiagnosticsServiceThe class provides a Diagnostics service manager for SharePoint. The class is residing in namespace Microsoft.SharePoint.Administration.We can use the static property named Local to get an instance of the service class; see:We can use the method WriteTrace() to write to the ULS log. The advantage of writing to the ULS log will be the following:
Note: Please note that the WriteEvent() method writes to the Windows Event Log and thus requires more Permissions. The windows event log entries can be viewed through the Windows Event Viewer.ExampleCreate a new SharePoint solution and add a Web Part into it. Add a button on the web part and add the following code in the button click event.
protected void Button1_Click(object sender, EventArgs e)
{
SPDiagnosticsCategory category = new SPDiagnosticsCategory(
"My Application Category",
TraceSeverity.Verbose,
EventSeverity.Verbose
);
SPDiagnosticsService.Local.WriteTrace(
0,
category,
"Log information"
}In the preceding code we have set the Trace Severity to Verbose. The Verbose level is used to specify log information which contains more details.The following are the members of the Trace Severity enumeration.Diagnostic Logging ConfigurationYou can configure the Log Levels in Central Administration. The following are the properties of diagnostics logging which are configurable:
Log file location
Number of Days to retain Log file
Least critical event level
Least trace event level
Enable Service Application Logs
To configure these open Central Administration > Monitoring > Configure diagnostics logging; see:On clicking the link you will get the following page:For testing our web part please make the levels to Verbose as shown below:Click the OK button to save the changes.Severity LevelsThe Severity Levels are used to specify the log information level. The Severity Level is used to process or discard log information by SharePoint.A Verbose level logging involves more writes to the hard disk and eating a lot of processor cycles too. Thus verbose level logging is recommended only for debugging purposes.The Event Throttling settings controls the severity of events captured in the Windows event log and the trace logs. As the severity decreases the number of events logged will increase.Testing the ApplicationWe can now test our web part. Build, Deploy and Insert the web part into a page. Click the button to create the trace log entry.You can view the entry from the log file (latest log file) in the 14 HIVE LOGS folder.This concludes our test with Diagnostics Logging.SPDiagnosticsServiceBaseSPDiagnosticsServiceBase is an abstract class. This class can be used to create a concrete class which can be used for writing custom diagnostics categories. Inside our implementation class the Category can be explicitly provided.Additionally you can specify the Product Name for the log entry while implementing the concrete class. Referenceshttp://tinyurl.com/sp2010-diag http://tinyurl.com/sp2010-spdiag http://tinyurl.com/sp2010-spdiagbase SummaryIn this article we have explored the debugging capabilities of SharePoint 2010 through logging. The following are the points worth noting:
The SPDiagnosticsService class is used for Logging
WriteEvent() writes to the Windows Event Log and needs Security Privileges
WriteTrace() writes to the SharePoint Trace Log
Central Administration can be used to configure Diagnostics Logging
SPDiagnosticsServiceBase provides an alternative way of Logging
Setting Up SharePoint 2016 Multi-Server Farm In Azure