Comment nettoyer régulièrement les fichiers journaux IIS ?
Comment nettoyer régulièrement les fichiers journaux IIS ?
I juste discovered that IIS builds up logs indefinitely et there ne appear to be tout IIS settings that will automatically clean out old log files. What is la meilleure façon de keep mon IIS logs under control so that they ne fill le entire hard drive?
Re: Comment nettoyer régulièrement les fichiers journaux IIS ?
You'll have to run a scheduled task to do it. Voici a Powershell script that should work.
```
set-location c:\windows\system32\Logfiles\W3SVC1\ -ErrorAction Stop
foreach ($File in get-childitem -include *.log) {
if ($File.LastWriteTime -lt (Get-Date).AddDays(-30)) {
del $File
}
}
```
Cela devrait purge anything that was dernier modified more than 30 days ago. Changez le path in le premier line to wherever votre log files are stored. Also changez le -30 to however long you want to retain le files. -30 means you will delete anything older than 30 days.
Vous pouvez have a look at [**this article**](http://technet.microsoft.com/en-us/library/dd347654.aspx) that shows différent properties for le FileInfo object si you ne want to use LastWriteTime.
```
set-location c:\windows\system32\Logfiles\W3SVC1\ -ErrorAction Stop
foreach ($File in get-childitem -include *.log) {
if ($File.LastWriteTime -lt (Get-Date).AddDays(-30)) {
del $File
}
}
```
Cela devrait purge anything that was dernier modified more than 30 days ago. Changez le path in le premier line to wherever votre log files are stored. Also changez le -30 to however long you want to retain le files. -30 means you will delete anything older than 30 days.
Vous pouvez have a look at [**this article**](http://technet.microsoft.com/en-us/library/dd347654.aspx) that shows différent properties for le FileInfo object si you ne want to use LastWriteTime.