SharePoint 2010 Write to ULS logger


/ Published in: C#
Save to your folder(s)

Modify as neccesary, add more areas.


Copy this code and paste it in your HTML
  1. public class LoggingService : SPDiagnosticsServiceBase
  2. {
  3. public static string MaventionDiagnosticAreaName = "Truck Seach";
  4. private static LoggingService _Current;
  5. public static LoggingService Current
  6. {
  7. get
  8. {
  9. if (_Current == null)
  10. {
  11. _Current = new LoggingService();
  12. }
  13.  
  14. return _Current;
  15. }
  16. }
  17.  
  18. private LoggingService()
  19. : base("My Solution Logging Service", SPFarm.Local)
  20. {
  21.  
  22. }
  23.  
  24. protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
  25. {
  26. var areas = new List<SPDiagnosticsArea>
  27. {
  28. new SPDiagnosticsArea(MaventionDiagnosticAreaName, new List<SPDiagnosticsCategory>
  29. {
  30. new SPDiagnosticsCategory("Truck Search Copy Pictures", TraceSeverity.Verbose, EventSeverity.Information)
  31. })
  32. };
  33.  
  34. return areas;
  35. }
  36.  
  37. public static void LogError(string categoryName, string Message)
  38. {
  39. SPDiagnosticsCategory category = LoggingService.Current.Areas[MaventionDiagnosticAreaName].Categories[categoryName];
  40. LoggingService.Current.WriteTrace(0, category, TraceSeverity.Verbose, Message);
  41. }
  42. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.