IIS logs are the requests from clients and written into text-based log files. It captures every web page/image/script requests. By default, IIS logs stored in C:\ of WFE servers. If SharePoint is being accessed a lot, It may cause disk space problems for your OS drive so quickly. So we can change this log path. Here is how:
- Go into IIS Manager for each WFE. (Start > run > Inetmgr)
- Select the server name in the Connections panel on the left.
- In the Features view shown in the middle panel, select Logging.
- For the log file, change the directory to a more suitable drive and folder. For example, I’ve changed the path for the log files to D:\Logs\IIS.
How about backing up them Monthly and deleting old logs?
It’s a good idea to back up and clean IIS Logs every Month. These Logs are highly compressible up to 500%!!! (Meaning 500 MB file to 5 MB file).
1. Download and import the PowerShell community Extension (for write-zip cmd-let)
2. Write the script to Zip and Delete IIS Logs
3. Schedule the script to run on every month ( or based on your schedule)
Step 1: Download and import the PowerShell community Extension
Download the PowerShell community Extension from https://pscx.codeplex.com/, and then unblock it (Right-click the downloaded .zip file > go to Properties > click on “Unblock” button)
Fire up PowerShell, Get it to your modules folder, typically it would be “C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules”
Extract the PowerShell community Extension Zip file to a folder, Say: pscx . Now, import the downloaded modules:
Step 2: Write the script to Zip and Delete IIS Logs
Now the next step: Writing PowerShell script to Zip and delete the Old log files, Here is the script:
Set-ExecutionPolicy RemoteSigned #important $date=get-date -UFormat %m-%d-%y write-zip -Path C:\Logs\IIS -Outputpath C:\Logs\$date.zip move-item c:\Logs\$date.zip D:\IISLogBackup\ get-childitem C:\Logs\IIS -include *.log -recurse | remove-item
Place the above script in to a file, Say: d:\Scripts\IISCleanup.ps1
Step 3: Schedule the script to run on every month
Finally, We need to schedule the script in the Windows Task Scheduler. Go to Start > All Programs > Administrative tools > Task Scheduler, and create the task to run the script at d:\Scripts\IISCleanup.ps1.
powershell.exe D:\scripts\IISLogsClear.ps1 If you get exceptions like “File not found..” then add the paths D:\Scripts, PowerShell’s path in System Environment variable.
Update: Here is my latest post on the same topic: PowerShell Script to compress and delete SharePoint ULS & IIS Logs