Write your tracking information to the SharePoint ULS log

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.