I am using log4net and other logging in my apps, and the logs are filling up the disks of the test server, so I created a Windows Scheduled Task to move logs to an archive disk, and also delete very old logs from the archive. I move logs older than 2 weeks to the archive and delete logs older than a year from that archive. I created this vb-script (started from the scheduled task) to do the job:
'VBScript that moves old log files from C:\LogFiles to E:\LogArchive
'Folders
Const FOLDER = "C:\LogFiles"
Const BACKUP_FOLDER = "E:\LogArchive"
'Objects
Dim objFSO, objFolder, objFolder2, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FOLDER)
'Loop and move
For Each objFile In objFolder.Files
If objFile.DateLastModified < DateAdd("w", -2, Now) Then
objFile.Move BACKUP_FOLDER & "\" & objFile.Name
End If
Next
'Delete very old files from target BACKUP_FOLDER
Set objFolder2 = objFSO.GetFolder(BACKUP_FOLDER)
For Each objFile In objFolder2.Files
If objFile.DateLastModified < DateAdd("w", -52, Now) Then
objFile.Delete
End If
Next
Plain old ASP-like code. No Types, everything is just Variant types.