I placed this code yesterday which focuses on deleting a file older the thirty days and this process checks after my streamwriter code the whole thing looks like this :
now the global config. Payment_Log_File_Loc is acutally C:\Temp on my local c drive so unless my permissions are set that I can't delete from there what else could be going on to fire off that exception ?Code:public LoggingAction( GlobalConfiguration globalConfig, PayFilePackageCol paymentfilePackCol) { GlobalConfig = globalConfig; PayFilePackCol = paymentfilePackCol; logfilePath1 = this.GlobalConfig.Payment_Log_File_Loc; String folder = Path.GetDirectoryName(logfilePath1); String fileName = Path.GetFileNameWithoutExtension(logfilePath1); String extension = Path.GetExtension(logfilePath1); String newName = folder + "\\" + fileName + "_" + ISO_Date() + extension; pSW = new StreamWriter(newName, true); string[] files = Directory.GetFiles(newName); foreach (string file in files) { FileInfo fi = new FileInfo(file); if (fi.LastAccessTime < DateTime.Now.AddDays(-30)) fi.Delete(); } } ~LoggingAction() {


Reply With Quote