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”.
Step 2.
Choose “Deploy as a sandboxed solution”.
Step 3.
Create a new ContentType and name it “LogMessage”. The Content type inherits from “Item”.
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" />
<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”.
Step 6.
Change the display name of the list definition to “Logs”.
Step 7.
Edit the xml of the ListTemplate.
- Remove OnQuickLaunch="TRUE"
- Add HiddenList="TRUE"
xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<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.
- Change the title to Logs
- Change the Url to Logs
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
Example of logmessage