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
23  Comments  |  Trackback Url  | 0  Links to this post | Bookmark this post with:        
 

Links to this post

Comments


Ethanael  commented on  Tuesday, January 24, 2012  2:28 PM 
Times are cnhaigng for the better if I can get this online!


yjnmuqw  commented on  Wednesday, January 25, 2012  10:08 AM 
ODS0uj <a href="http://vxeadofqrzef.com/">vxeadofqrzef</a>


yrkwnblcif  commented on  Thursday, January 26, 2012  10:14 AM 
W4n75S , [url=http://wbzqcfncuwsn.com/]wbzqcfncuwsn[/url], [link=http://fsntodizpohx.com/]fsntodizpohx[/link], http://unplqbqbboey.com/


arielgetsnice  commented on  Tuesday, January 31, 2012  4:41 AM 
accutane >:OOO propecia >:OOO


Arkheart  commented on  Saturday, February 18, 2012  3:02 AM 
If youre still experiencing problems try to schedule a job on the sql server wich shrinks does the above actions. I think this will help with your problem. i had the same problem but with a normal c# program



fireyourmom  commented on  Monday, February 20, 2012  2:44 AM 
Thanks Alexandra. I can see myself getting a lot of use out of this sweater! Bonus points that it's handmade by Nanny and passed down in the family. xo



qlenesvm  commented on  Thursday, April 19, 2012  10:18 PM 
qlenesvm


ihgdqzw  commented on  Saturday, April 21, 2012  1:17 AM 
ihgdqzw


adzdvpww  commented on  Monday, April 23, 2012  6:42 PM 
adzdvpww


sttgtpkf  commented on  Thursday, April 26, 2012  10:32 PM 
sttgtpkf


kjelwi  commented on  Saturday, April 28, 2012  1:19 AM 
kjelwi


mnhuvdb  commented on  Thursday, May 03, 2012  9:00 PM 
mnhuvdb


stepoo  commented on  Friday, May 04, 2012  9:02 PM 
stepoo


mvxaza  commented on  Saturday, May 05, 2012  10:24 PM 
mvxaza


wiotnjr  commented on  Thursday, May 10, 2012  9:06 PM 
wiotnjr


qliunt  commented on  Thursday, May 10, 2012  10:33 PM 
qliunt


hbxfmv  commented on  Friday, May 11, 2012  8:24 PM 
hbxfmv


dhjoox  commented on  Friday, May 11, 2012  11:26 PM 
dhjoox


drtmdm  commented on  Monday, May 14, 2012  7:07 PM 
drtmdm


rpxarsf  commented on  Monday, May 14, 2012  8:46 PM 
rpxarsf


nlpjrl  commented on  Tuesday, May 15, 2012  7:51 PM 
nlpjrl


hrmcmt  commented on  Wednesday, May 16, 2012  8:35 PM 
hrmcmt


Replica handbags  commented on  Thursday, May 17, 2012  10:23 AM 
Let us all face it the actual desk can be invariably tiny therefore absolutely no room to the bag up for grabs alone <strong><a href="http://www.3areplicahandbags4u.com/">Replica handbags</a></strong>. Putting your current ladies handbag in your lap is incredibly uncomfortable in order that simply leaves a floor. mzxbudui@pp.com

Name *:
URL:
Email:
Comments:


CAPTCHA Image Validation