SharePoint 2010中增强的错误跟踪机制

      在SharePoint 2007中,调试和跟踪错误最常用的方法就是查看日志(C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS),
但是由于日志中记录太多,给查找错误带来很多不便,那个友好的提示页面总是让人又爱又恨,尽管也有两种其他办法,请参阅MOSS中如何快速定位错误之一--通过查看日志MOSS中如何快速定位错误之二--让页面显示错误  。
    在SharePoint 2010中,增强了错误跟踪,日志文件还是在同样的目录下,但是当你得到一个错误时,无论产生自SharePoint 网站还是自定的Web part,错误信息多了一项“Correlation ID”。
    比如,我手工去产生一个错误,在之前SharePoint 2010中使用Visual Studio 2010进行方便快速的Web Part开发创建的web part里添加一句错误代码:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
            SPSite site = new SPSite("http://microsoft.com");   //错误代码

            if (this.RadioButtonList1.SelectedItem.Text == "YaoYao")
            {
                this.imgBeauty.ImageUrl = @"_layouts/Images/myfirstwebpart/chinayaoyao.jpg";
            }
            else
            {
                this.imgBeauty.ImageUrl = @"_layouts/Images/myfirstwebpart/Elly.jpg";
            }
}
第一句代码在这个Web part部署到页面上时一定会产生一个错误,如图:

     通过这个Correlation ID我们能够非常方便的在日志中定位错误,打开最新的日志文件(C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS):
查找这个ID,上图我的是248d228e-ac94-4ed9-9c4e-5767c311ab9d,可以非常方便的找到错误提示信息:


以下是我得日志信息,提示我找不到microsoft.com这个站点,检查输入的URL是否正确:


01/19/2010 10:18:01.55         w3wp.exe (0x1534)                               0x1440        SharePoint Foundation                 Runtime                               tkau        Unexpected        System.IO.FileNotFoundException: The Web application at http://microsoft.com/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.    at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)     at Microsoft.SharePoint.SPSite..ctor(String requestUrl)     at MyFirstWebPart.VisualWebPart1.VisualWebPart1UserControl.RadioButtonList1_SelectedIndexChanged(Object sender, EventArgs e)     at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)     at System.Web.UI.Page.RaiseChangedEvents()     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, ...        248d228e-ac94-4ed9-9c4e-5767c311ab9d

 

来源:http://www.cnblogs.com/fatwhale/archive/2010/03/01/1675427.html

posted @ 2010-09-15 15:46  绿森林  阅读(220)  评论(0编辑  收藏  举报