Remove Logs

A couple of our web servers were running into some issues with disk space. Turns out the logs weren’t being cleaned up properly. In order to remediate this, I wrote a function that can be reused anywhere. The function accepts 3 parameters: FilePath: The directory where you want to remove the logs from CutOff; Specifies the age (in days) that a file must have before being deleted. LogPath; This parameter specifies the directory where you want the CSV log file. If this is left open, no CSV will be saved. Example As an example, I’m going to remove all files, older than 30 days, from the folder “C:\temp\W3SVC2030036971\W3SVC2030036971". I want a CSV log to be written in the “C:\temp” folder. ...

6 September, 2016 · 4 min · Maarten Van Driessen