Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to delete log files created by my Silverlight application on IIS in a way that the server should check log files older than "n" number of days and delete them automatically.

Is there any configuration in IIS that can do this task or I should write my own utility for it?

share|improve this question
When you think your question is answered, you should mark a question as the right answer. Doing so will make the question apear as solved. – Jonathan Jan 27 '12 at 8:58
up vote 4 down vote accepted

There is no configuration switch I'm aware of. You can use the following Powershell script to delete logfiles older than 7 Days in C:\WIN2003\system32\LogFiles\SMTPSVC1 and C:\WIN2003\system32\LogFiles\W3SVC1.

dir C:\WIN2003\system32\LogFiles\SMTPSVC1 |? {$_.LastWriteTime -lt (get-date).AddDays(-7)} | del
dir C:\WIN2003\system32\LogFiles\W3SVC1 |? {$_.LastWriteTime -lt (get-date).AddDays(-7)} | del

Then start this as a planned task once every day. Run the command C:\WIN2003\system32\WindowsPowerShell\v1.0\powershell.exe -file C:\Batch\cleanupLogfiles.ps1 in C:\WIN2003\system32\WindowsPowerShell\v1.0 dir. For this example I assuemed your windows is installed in C:\WIN2003 and your script is C:\Batch\cleanupLogfiles.ps1

share|improve this answer
Jon, thanks for the answer.. but my requirement is to automatically delete log files(created by application in a folder on website's virtual directory) without any intervention of a user/admin. – asif Jan 25 '12 at 10:35
See update above – Jonathan Jan 25 '12 at 13:53
@asif Any more questions? – Jonathan Jan 26 '12 at 7:51
thanks, that was helpful. – asif Jan 26 '12 at 11:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.