Menu

Clear old log fles

Help
Greg Grewe
2014-06-16
2014-06-16
  • Greg Grewe

    Greg Grewe - 2014-06-16

    In case anyone is interested, I added the following to clear log files after "x" days. It seems to be working well.

    Added LogFilesToKeep to Web.Config with a value of "21"
    Created the method below in util.cs;
    public static void clearLoggingFiles()
    {
    int lnDaysToKeep = Convert.ToInt16(Util.get_setting("LogFilesToKeep","21"));
    string[] laFiles = Directory.GetFiles(Util.get_log_folder());

            foreach (string lsFile in laFiles)
            {
                FileInfo loFileInfo = new FileInfo(lsFile);
                if (loFileInfo.LastWriteTime < DateTime.Now.AddDays(-lnDaysToKeep))
                {
                    try
                    {
                        loFileInfo.Delete();
                    }
    
                    catch (Exception ex)
                    {
                        write_to_memory_log(ex.Message + "; Error deleting old log files.");
                    }
                }
            }
        }
    

    Modified write_to_log() in util.cs to call clearLoggingFiles()

     
  • Corey Trager

    Corey Trager - 2014-06-16

    thanks

     

Log in to post a comment.