The custom webpart, event handler, and workflow in SharePoint are very common. These integrated items are difficult to troubleshoot if an error is reported. This article lists simple methods for using ULS logs.
Refer to the following documents to learn how to write information to the ULS log.
====================
SharePoint trace logs and the unified Logging Service (ULS)
Http://weblogs.asp.net/erobillard/archive/2008/07/31/sharepoint-trace-logs-and-the-unified-logging-service-uls.aspx
Writing to the trace log
Http://msdn.microsoft.com/en-us/library/aa979595.aspx
Trace log example
Http://msdn.microsoft.com/en-us/library/aa979522.aspx
If you know how to write, you also need to know what to write. the most required information for troubleshooting is the location of the error code. after knowing the location, you can expand the corresponding conjecture, verify, or add the log output of some suspicious object field values.
The following code snippet shows how to get the wrong row number from the exception.
static void Main(string[] args){ try { Fun1(); } catch (Exception ex) { System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true); Console.WriteLine(trace.GetFrame(0).GetMethod().Name); //Get deepest error function. Console.WriteLine("Line: " + trace.GetFrame(0).GetFileLineNumber()); //Get error line number. Console.WriteLine("Column: " + trace.GetFrame(0).GetFileColumnNumber()); Console.WriteLine(ex.ToString());//All in one! This one is simplest. }}static void Fun1(){ throw new Exception("An error has happened");}
The getframe (INDEX) method of system. Diagnostics. stacktrace can obtain the stackframe object. The index of the stack frame starts from 0, and 0 is the stackframe of the last stack.