Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS 7 Log Files Auto Delete?

Tags:

asp.net

iis-7

Is there any feature in IIS 7 that automatically deletes the logs files older than a specified amt of days?

I am aware that this can be accomplished by writing a script(and run it weekly) or a windows service, but i was wondering if there is any inbuilt feature or something that does that.

Also, Currently we turned logging off as it is stacking up a large amount of space. Will that be a problem?

like image 838
CodingSlayer Avatar asked Aug 02 '11 22:08

CodingSlayer


People also ask

Can IIS log files be deleted?

Delete Old Log Files by the IIS Log Cleaner Tool. IIS Log Cleaner is a simple tool for enacting a log retention policy for IIS. The tool runs in the background (once every hour) and cleans up the IIS log folder automatically, deleting log files older than a maximum age that you set.

Can I delete C :\ Inetpub logs LogFiles?

Yes, it's safe to delete the IIS logs.

Can W3SVC1 log files deleted?

These log files are produced by Microsoft Internet Information Services. By default: The files are simply log files of accesses to the Web server. It is safe to delete all the old log files.


3 Answers

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

Set your 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 the log files that are one week or older.

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

like image 56
Ido Sela Avatar answered Sep 25 '22 23:09

Ido Sela


One line batch script:

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

Modify the /d switch to change number of days a log file hangs around before deletion. The /s switch recurses subdirectories too.

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

like image 37
jamaco Avatar answered Sep 23 '22 23:09

jamaco


Similar solution but in powershell.

I've 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 removes all files in the D:\IISLOgs folder older than 15 days.

like image 34
PatoLoco Avatar answered Sep 21 '22 23:09

PatoLoco