Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.