Archive for February, 2011

More on adding to ULS logs

Wednesday, February 9th, 2011

Add this to a class, or anywhere accessible, and notes can be added to ULS logs to help with coding.

public static void AddNoteToULS(string thetitle, string themessage)
{
SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
diagSvc.WriteTrace(0, new SPDiagnosticsCategory(thetitle, TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable,
“Writing to the ULS log: {0}”, new object[] { themessage });
}

Quick way to add an error or not to ULS logs

Wednesday, February 9th, 2011

Here’s a quick neat snippet to add a comment to ULS logs. Helps to troubleshoot those hard errors.

using microsoft.sharepoint.administration;

try
{
//some code;
}
catch (Exception ex)
{
SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
diagSvc.WriteTrace(0, new SPDiagnosticsCategory(“EMACS CUSTOM”, TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable,
“Writing to the ULS log: {0}”, new object[] { ex.ToString() });
}