By default, IIS logs activity to the W3SVC1 folder. This folder can consume a fair amount of disk space over time and eventually interfere with production activity if you don’t trim the log files.
These log files are mainly for troubleshooting and reviewing security, so there is typically no need to keep them indefinitely. Ways to manage them include:
- Turn on NTFS compression.
- Zip up older log files.
- Move older log files to another location.
- Delete older log files.
- Turn off logging altogether.
Scripts can be written to handle some of these options for you, such as the following command which assigns a scheduled task to delete log files older than 30 days at midnight on Sundays:
at 12:00 /EVERY:Su Forfiles.exe -p C:\WINDOWS\system32\LogFiles\W3SVC1 -m *.log -d -30 -c \”Cmd.exe /C del @path\”
at 12:00 /EVERY:Su Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -30 -c \”Cmd.exe /C del @path\”
(The back slash after the -c flag (…-c \”Cmd.exe…) is required if you want to schedule the FORFILES.EXE command with AT. If you are just running the command on its own, you don’t need the backslash.)