In this SharePoint tutorial, we will learn everything about, SharePoint ULS Logs, like:
- What are different ways to check logs in SharePoint
- What are SharePoint ULS logs
- How to view SharePoint ULS logs using SharePoint log viewer
- Change SharePoint uls logs location
- How to find SharePoint uls log details based on correlation id using PowerShell
- How to write custom message to SharePoint 2013 ULS Logs Programmatically
OUR LATEST VIDEOS
Let us see what are the different ways to check error logs in SharePoint 2013/2016/2019. If any error occurred in your SharePoint environment, then it is necessary to get the logs. Below is the area where we should check for SharePoint logs:
1. Event Viewer
This is one of the popular places to search for SharePoint errors.
You can open this by using the command like this:
Start -> Run and then enter eventvwr and click on Ok. This will open the Event Viewer window.
It has a separate section for SharePoint with a name as Windows SharePoint Services. Apart from this, you can also check in the Windows Logs -> Applications section for errors.
By default, SharePoint maintains log inside the 14/15 hive folder, which is located in
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14/15\LOGS
You can check in the above locations also.
You can use ULS log viewer tool to see logs from 14 hive folder. This is a good tool.
3. IIS logs
You can also check in IIS logs for some errors.
The IIS logs presented in C:\Windows\System32\LogFiles location.
The IIS logs contain information about each request and the response.
Apart from this you can also enable tracing in SharePoint by modifying in the web.config file like below:
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Merge-SPLogFile -Path "E:\Bijay\TempError.txt" -Correlation ff3a479d-8e3b-a03f-6251-ce47ef2463c6 -Overwrite
Make sure you have write access to the E:\Bijay\ folder.
Once you run the command, it will pull the logs from all the servers and it will write in the text file.
Similarly, also you can use get-splogevent command to retrieve logs based on the correlation id.
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
get-splogevent | ?{$_.Correlation -eq "da80689d-e397-70c8-65fd-34a7bc8a5446"} | select Area, Category, Level, EventID,Message | Format-List > E:\errorlog.txt
Merge-SPLogFile cmdlet combines trace log entries from all farm computers into a single log file on the local computer. You can run this command from PowerShell.
This will be very much helpful if you are working in a multi-server environment. As SharePoint maintains log entries in each server, by using this command you can pull them in a single file.
You can filter based on various criteria like StartTime and EndTime, Process, Area, Category, EventID, and Message etc.
Below is the full syntax according to Microsoft.
Merge-SPLogFile -Path "C:\Logs\FarmMergedLog.log" -Overwrite
Example-2:
Merge-SPLogFile -Path "C:\Logs\FarmMergedLog.log" -Overwrite -Level High
Example-4: (merges based on a Correlation ID)
Merge-SPLogFile -Path "C:\Logs\FarmMergedLog.log" -Overwrite -StartTime "06/09/2008 16:00" – EndTime "06/09/2008 16:15"
Merge-SPLogFile Correlation ID Cmdlet did not return any records in the log file
While working with Merge-SPLogFile PowerShell command, you might come across an error as Cmdlet did not return any records in the log file. Check your time range or filters.
We run the below PowerShell cmdlet to get SharePoint error details from ULS logs.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$diagSvc = [Microsoft.SharePoint.Administration.SPDiagnosticsService]::Local
$category = new-object Microsoft.SharePoint.Administration.SPDiagnosticsCategory("My Custom Category",
[Microsoft.SharePoint.Administration.TraceSeverity]::Monitorable,
[Microsoft.SharePoint.Administration.EventSeverity]::Error )
$diagSvc.WriteTrace(0, $category, [Microsoft.SharePoint.Administration.TraceSeverity]::Monitorable, "This is our custom error message writted from PowerShell" )
After this if you want to check in USL log files you can see it will write like below:
SPDiagnosticsCategory category = new SPDiagnosticsCategory("My Custom Category",TraceSeverity.High,EventSeverity.ErrorCritical);
SPDiagnosticsService.Local.WriteTrace(0,category,TraceSeverity.High,"This is our custom error message writted from SharePoint 2013 Server object model");
I hope this will be helpful to Write to ULS log using PowerShell and programmatically using the SharePoint server object model.
You may like the following SharePoint tutorials:
- SharePoint web application
- PowerShell SharePoint site collection example
- SharePoint list delete title column
- SharePoint list operations using rest api
- SharePoint modern list view customization example
- Create SharePoint list view
- SharePoint event receiver example
In this SharePoint tutorial we learned about SharePoint ULS logs.
- Different ways to check logs in SharePoint
- SharePoint ULS logs
- View SharePoint ULS logs using SharePoint Log Viewer
- Change SharePoint ULS Logs Location
- Find SharePoint ULS logs based on correlation id using PowerShell
- Write to SharePoint 2013 ULS Logs Programmatically