Unlike Apache's built-in log rotation, IIS 6.0 requires manual configuration or scripting for proper log management. Here are the native options available:
1. IIS Manager -> Website Properties -> Website tab -> Enable logging
2. Select "W3C Extended Log File Format"
3. Under "Properties", configure:
- New log schedule (hourly/daily/weekly/monthly)
- Log file directory
- File naming convention
The built-in rotation only creates new files - it doesn't automatically delete old logs. For proper log rotation including deletion, you'll need additional solutions.
Here's a robust PowerShell script that handles both rotation and deletion:
# IIS Log Rotation and Cleanup Script
$logPath = "C:\inetpub\logs\LogFiles"
$retentionDays = 30
Get-ChildItem -Path $logPath -Recurse -File | Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-$retentionDays)
} | Remove-Item -Force
# Compress logs older than 7 days
Get-ChildItem -Path $logPath -Recurse -File | Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-7) -and $_.Extension -ne ".zip"
} | ForEach-Object {
Compress-Archive -Path $_.FullName -DestinationPath "$($_.DirectoryName)\$($_.BaseName).zip"
Remove-Item -Path $_.FullName
}
For larger Windows environments, consider these commercial tools:
- SolarWinds Log & Event Manager
- ManageEngine EventLog Analyzer
- Paessler PRTG Network Monitor
To automate the PowerShell script:
1. Open Task Scheduler
2. Create Basic Task
3. Set trigger to "Daily"
4. Action: "Start a program"
5. Program: powershell.exe
6. Arguments: -ExecutionPolicy Bypass -File "C:\scripts\iis_log_rotation.ps1"
7. Run with highest privileges
Microsoft's LogParser tool can help analyze and rotate logs:
LogParser.exe -i:IISW3C -o:IISW3C
"SELECT * INTO 'C:\logs\archive\ex%YY%%MM%%DD%.log'
FROM 'C:\inetpub\logs\LogFiles\W3SVC1\ex*.log'
WHERE TO_DATE(date) < SUB(SYSTEM_DATE(), 30)"
Unlike Apache's built-in log rotation, IIS 6.0 requires explicit configuration for log management. The W3C Extended Log File Format is IIS's default, storing logs in %SystemDrive%\inetpub\logs\LogFiles
by default.
IIS 6.0 offers basic rotation through the IIS Manager:
- Open IIS Manager
- Right-click the website → Properties
- Under Web Site tab → Enable logging
- Click Properties → New Log Time Period
Available rotation intervals: Hourly, Daily, Weekly, Monthly. For example, to set daily rotation:
adsutil.vbs SET W3SVC/LogType 1
adsutil.vbs SET W3SVC/LogFilePeriod 1 # 0=Never, 1=Daily, 2=Weekly, 3=Monthly
For automatic deletion of old logs, create a scheduled task with this VBScript (save as PurgeIISLogs.vbs
):
Const LOG_DIR = "C:\inetpub\logs\LogFiles"
Const DAYS_TO_KEEP = 30
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set folder = objFSO.GetFolder(LOG_DIR)
For Each file In folder.Files
If DateDiff("d", file.DateCreated, Now) > DAYS_TO_KEEP Then
If LCase(objFSO.GetExtensionName(file.Name)) = "log" Then
file.Delete(True)
End If
End If
Next
Windows shops typically use:
- Microsoft Log Parser: Powerful query-based log analysis
- LogRhythm: SIEM with log rotation capabilities
- Splunk: Enterprise log management with retention policies
Though you're on Server 2003, this PowerShell snippet works on newer versions:
Get-ChildItem "C:\inetpub\logs\LogFiles\*.log" |
Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} |
Remove-Item -Force
- Store logs on separate physical disks from OS
- Compress old logs before deletion (use WinRAR command line)
- Consider centralizing logs with Windows Event Collector
- Document rotation schedule in change management systems