IIS 7 Auto Delete Log Files?

Is there any feature in IIS 7 that automatically deletes log files older than a specified number of days?

I know this can be done by writing a script (and running it weekly) or a Windows service, but I was wondering if there was any built-in function or something that does this.

In addition, we are currently disconnected, as it adds up a large amount of space. Would this be a problem?

+47
iis-7
Aug 2 2018-11-21T00:
source share
4 answers

You can create a task that runs daily using Administration> Task Scheduler.

Define a task to run the following command:

forfiles /p "C:\inetpub\logs\LogFiles" /s /m *.* /c "cmd /c Del @path" /d -7 

This command is for IIS7, and it deletes all log files that are weeks or older.

You can adjust the number of days by changing the value of /d arg.

+90
May 13 '12 at 20:10
source share

One batch of lines of script:

 forfiles /p C:\inetpub\logs /s /m *.log /d -14 /c "cmd /c del /q @file" 

Change the / d switch to change the number of days the log file hangs before being deleted. The / s option also loads subdirectories.

Link: http://debug.ga/iis-log-purging/

+3
Sep 21 '15 at 5:43
source share

A similar solution, but in powershell.

I set a task to run powershell with the following line as an argument.

 dir D:\IISLogs |where { ((get-date)-$_.LastWriteTime).days -gt 15 }| remove-item -force 

It deletes all files in the folder D: \ IISLOgs older than 15 days.

+1
Jan 15 '14 at 9:34
source share

Another viable single layer Powershell:

 Get-ChildItem -Path c:\inetpub\logs\logfiles\w3svc*\*.log | where {$_.LastWriteTime -lt (get-date).AddDays(-180)} | Remove-Item -force 

In case $_.LastWriteTime does not work, you can use $PSItem.LastWriteTime instead.

For more information and other recommendations on using disk space for IIS LogFiles disk space, I also suggest reading this post .

0
Nov 21 '16 at 2:03
source share



All Articles