using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
public class ULSLogging : SPDiagnosticsServiceBase
{
public static string DiagnosticAreaName = "CodeChallege
LOG";
private static ULSLogging _Current;
public static ULSLogging Current
{
{
if (_Current == null)
{
_Current = new ULSLogging();
}
return _Current;
}
}
private ULSLogging()
:
base("CodeChallege
Logging Service", SPFarm.Local)
{
}
protected override IEnumerable<SPDiagnosticsArea>
ProvideAreas()
{
List<SPDiagnosticsArea>
areas = new List<SPDiagnosticsArea>
{
new SPDiagnosticsArea(DiagnosticAreaName,
new List<SPDiagnosticsCategory>
{
new SPDiagnosticsCategory("CodeChallege", TraceSeverity.Unexpected,
EventSeverity.Error)
})
};
return areas;
}
public static void LogError(string
categoryName, string errorMessage)
{
SPDiagnosticsCategory category = ULSLogging.Current.Areas[DiagnosticAreaName].Categories[categoryName];
ULSLogging.Current.WriteTrace(0, category, TraceSeverity.Unexpected, errorMessage);
}
}
}
in Catch block call above methode as below:-
ULSLogging.LogError("CodeChallege",
ex.Message);
No comments:
Post a Comment