One of the best things to do in your SharePoint environment is to relocate your log files to a central location. This gets them off of the C drive and easier to find during troubleshooting of issues. This change is pretty simple to do in PowerShell, but could cause an error and confusion if you overlook an important step.
Here is the command to change the log file directory:
Set-ItemProperty ‘IIS:\Sites\SharePoint – 80’ -name logFile.directory -value ‘C:\Logs\IIS’
Make sure to change “SharePoint – 80” to the name of the IIS site that you would like to change the log directory. Also, change the value parameter to the path that you have designated for your log file location. Note: I would not put the log files on the C drive – I just have it as the C drive since this is a small virtual machine I’m using.
Pop open the SharePoint 2010 Management Shell and enter the above command to change the log file directory: (Start > All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell)
Opps, we got an error! The error states that it cannot find the IIS drive. This tells us that the IIS snap-in has not been loaded. Let’s load that now using Import-Module WebAdministration.
Once you have imported the IIS snap-in, press the up arrow key and re-run the command to change the log directory:
Now, open up the IIS Manager console, expand Sites, click on the site you changed the log directory for and double click on Logging under the IIS section. You should see the new directory location under Log File.
Completed! If you have the schedule set to “Daily”, then you will not see a log file within the new path until the next day. Also, if you desire, you can manually move the old log files into this new location. Keep in mind that this log directory change will not replicate to other servers. So, you will need to perform this on each server.
_____________________
Sponsors *Trusted SharePoint Ads Only!*
Packaged Enterprise Search
for SharePoint.View a quick online demo here! Surfray.com/Ontolica
Free Outlook Sidebar!
Access SharePoint from Outlook w/ harmon.ie Sidebar. Download Now!
SharePoint Migration Tools
Sharegate: No-Brainer Migration Tools for SharePoint. $375.
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
8 Tips to Increase SharePoint Adoption
Download Free Whitepaper
07/19/2010 at 9:52 am
Is there a way to change it universally at the Server level rather than at the individual site level?
10/08/2010 at 3:46 am
Also, have you found a way to to set and move the SP Logs using Powershell..?
Want to set and move them to the D: drive on my servers, as part of my install script. Will save the manual configuration changes after the install…..
ta
Dongers
10/08/2010 at 3:50 am
Found it!!!!
http://www.alpesh.nakars.com/blog/powershell-to-change-sharepoint-diagnostic-log-file-location/
Useful!!!!!
02/16/2011 at 6:22 pm
I moved my log files via IIS Manager, but web analytics reports are empty. I assume it’s because it web analytics service cannot find the logs.
Does setting the properties via PowerShell take care help?
04/04/2012 at 7:53 pm
If you want to change log file location for all sites on IIS server in one step, here is a simple PS code:
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Web.Administration”)
$iis = new-object Microsoft.Web.Administration.ServerManager
$iis.SiteDefaults.LogFile.Directory = “C:\Logs\IIS\”
$iis.CommitChanges()
04/04/2012 at 9:20 pm
Excellent, thanks for providing this!