{"id":1431,"date":"2012-05-18T13:11:06","date_gmt":"2012-05-18T13:11:06","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=1431"},"modified":"2024-05-13T10:44:33","modified_gmt":"2024-05-13T10:44:33","slug":"writing-to-uls-from-within-c","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/writing-to-uls-from-within-c\/","title":{"rendered":"Writing To ULS From Within C#"},"content":{"rendered":"<h2>Writing to ULS From Within C#<\/h2>\n<p>Event Receivers and Feature Receivers are notoriously hard to debug.\u00a0 Here\u2019s a little gem to ease your debugging migraines:<\/p>\n<p>Here\u2019s the function I use, just to simplify subsequent calls:<\/p>\n<pre lang=\"php\"> private void LogOut(TraceSeverity Level, string OutStr)\r\n        {\r\n            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(\"SuperRouter Updated\", Level, EventSeverity.Error), TraceSeverity.Unexpected, OutStr, null);\r\n        }<\/pre>\n<p>Here\u2019s \u00a0what the call looks like. Note you can set the severity level.\u00a0 I sprinkle these throughout the code and dump data etc throughout<\/p>\n<div><\/div>\n<pre lang=\"php\">LogOut(TraceSeverity.High, \"Item Updated Event Trapped!\");<\/pre>\n<p>Here\u2019s the reference to use in the code:<\/p>\n<pre lang=\"php\">using Microsoft.SharePoint.Utilities;\r\nusing Microsoft.SharePoint.Administration;<\/pre>\n<p>If you\u2019d like a class to reuse, here it is:<\/p>\n<pre lang=\"php\">public class MyLogger\r\n   {\r\n       public static void LogOut(TraceSeverity Level, string OutStr)\r\n       {\r\n           SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(\"JoelER\", Level, EventSeverity.Error), TraceSeverity.Unexpected, OutStr, null);\r\n       }\r\n   }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Writing to ULS From Within C# Event Receivers and Feature Receivers are notoriously hard to debug.\u00a0 Here\u2019s a little gem to ease your debugging migraines: Here\u2019s the function I use, just to simplify subsequent calls: private void LogOut(TraceSeverity Level, string OutStr) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(&#8220;SuperRouter Updated&#8221;, Level, EventSeverity.Error), TraceSeverity.Unexpected, OutStr, null); } Here\u2019s \u00a0what the [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":1222,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[28],"tags":[],"class_list":["post-1431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=1431"}],"version-history":[{"count":2,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1431\/revisions"}],"predecessor-version":[{"id":3955,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1431\/revisions\/3955"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/1222"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=1431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=1431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=1431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}