SharePoint 365 logging   

Tags: SharePoint 365, Sandboxed, Logging
Technorati Tags: , ,

With SharePoint 365 OOB it isn’t possible as developer to read the log files. When you get an error you have to copy the correlation id and send it to Microsoft. Then it depends on Microsoft how fast this error will be resolved :).

 

SharePoint list to the rescue :). the solution is very simple, you have to log your errors as a list item.

 

SharePoint 365 Log list

 

Step 1.

Create a new “Empty SharePoint project” and name it “SharePoint365LogList”.

image

 

Step 2.

Choose “Deploy as a sandboxed solution”.

image

 

Step 3.

Create a new ContentType and name it “LogMessage”. The Content type inherits from “Item”.

image

 

Step 4.

Add the following fields. Feel free to change the field Guid :).

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field Name="VNTGStackTrace" ID="{93F3B2C8-1204-494F-9B9C-E6438D00C3FC}" DisplayName="Stack Trace"
         Type="Note" Required="FALSE" Group="Office 365 - VNTG Log" />
  <Field Name="VNTGMessage" ID="{8BEAAA59-0EFC-4A8A-AC2A-706DC94FA66D}" DisplayName="Message"
         Type="Note" Required="FALSE" Group="Office 365 - VNTG Log" />
  <Field Name="VTNGParameters" ID="{1595CF29-D9F8-4950-AD47-7227F7F038D2}" DisplayName="Parameters"
         Type="Note" Required="FALSE" Group="Office 365 - VNTG Log" />
  <Field Name="VTNGUsername" ID="{634A0108-B175-4959-BC60-2A3C0B0195E0}" DisplayName="Username"
         Type="User" Required="FALSE" Group="Office 365 - VNTG Log" />
  <Field Name="VTNGErrorCategory" Required="FALSE" ID="{682F567A-2045-4DDB-ADB6-31375C48E8AD}" DisplayName="Category"
         Type="Note" Group="Office 365 - VNTG Log" />
  
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x0100fac0ca812e274a1fa2dce6c845bc10b5"
               Name="LogMessage"
               Group="Office 365 - VNTG Log"
               Description="Office 365 - VNTG Log"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef Name="VNTGStackTrace" DisplayName="Stack Trace" ID="{93F3B2C8-1204-494F-9B9C-E6438D00C3FC}"/>
      <FieldRef Name="VNTGMessage" DisplayName="Message" ID="{8BEAAA59-0EFC-4A8A-AC2A-706DC94FA66D}"/>
      <FieldRef Name="VTNGParameters" DisplayName="Parameters" ID="{1595CF29-D9F8-4950-AD47-7227F7F038D2}"/>
      <FieldRef Name="VTNGUsername" DisplayName="User" ID="{634A0108-B175-4959-BC60-2A3C0B0195E0}"/>
      <FieldRef Name="VTNGErrorCategory" DisplayName="Category" ID="{682F567A-2045-4DDB-ADB6-31375C48E8AD}"/>
    </FieldRefs>
  </ContentType>
</Elements>

 

Step 5.

Add a new list based on the content type LogMessage. Name the list “Logs”.

image

 

Step 6.

Change the display name of the list definition to “Logs”.

image

 

Step 7.

Edit the xml of the ListTemplate.

  1. Remove  OnQuickLaunch="TRUE"
  2. Add HiddenList="TRUE"
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->
    <ListTemplate
        Name="Logs"
        Type="10000"
        BaseType="0"
        SecurityBits="11"
        Sequence="410"
        DisplayName="Logs"
        Description="My List Definition"
        Image="/_layouts/images/itgen.png"
        HiddenList="TRUE"/>
</Elements>

 

Step 8.

Edit the xml of the listinstance.

  1. Change the title to Logs
  2. Change the Url to Logs
  3. <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ListInstance Title="Logs"
                    OnQuickLaunch="TRUE"
                    TemplateType="10000"
                    Url="Logs"
                    Description="My List Instance">
      </ListInstance>
    </Elements>

Step 9.

Package the solution and deploy it to your SharePoint 365.

 

Step 10.

Logging errors is only possible in custom code. When you catch an error you have to create a new list item en save the list item in the lists.

example method:

public void LogError(SPWeb web, Exception ex, string category)
{
    SPList l = web.GetList("Logs");
    SPListItem item = l.Items.Add();
 
    item["Title"] = ex.Message;
    item["StackTrace"] = ex.StackTrace;
    item["Message"] = ex.ToString();
    item["Username"] = web.CurrentUser;
    item["ErrorCategory"] = category;
 
    item.Update();
}

 

Example view of the error list

image

 

Example of logmessage

image

 
Posted by  Gilissen Timmy  on  12/26/2011
0  Comments  |  Trackback Url  | 0  Links to this post | Bookmark this post with:        
 

Links to this post

Comments

Name *:
URL:
Email:
Comments:


CAPTCHA Image Validation