This is something I see a lot, IIS logs takes a lot of space and sometimes even cause the IIS Server to stop due to “Not Enough Space” exception.
There is not a build in solution for Log retention policy but several options on File Size, Creation Scheduling etc.
There are many solutions for cleaning the Logs but I prefer the Task Scheduler way with a single line for cleaning Logs based on their creation date.
Run Task Scheduler from the Command Line
- Open a command prompt. To open a command prompt, click Start , click All Programs , click Accessories , and then click Command Prompt .
- At the command prompt, type Taskschd.msc .
Create Clean IIS Log Task
Create new Task and specify “Start a program” in Actions Tab, enter “forfiles” in “Program/script:” section,
And “/p “C:\inetpub\logs\LogFiles” /s /m *.* /c “cmd /c Del @path” /d -2” in Arguments
(You can change -2 depends on the amount of days you want to keep your IIS Logs)
Full Command Line:
forfiles /p “C:\inetpub\logs\LogFiles” /s /m *.* /c “cmd /c Del @path” /d -2
You can also download and import the Task – Clear IIS Logs.xml