/// <summary> /// determines if multiple files are needed trims files if out of range which file is /// current /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool ManageSequentialLogs() { lock (LogFileLock) { // Reformat logFileName to include version number // Search directory for existing files in format of Config.LogFileName.####.ext if (!LoggingIsEnabled) { return(true); } string logFile = LogFileName; List <string> tempList = PruneLogFiles(EnumerateLogFiles(logFile, "[0-9]{0,4}", true)); // set current log if (tempList.Count > 0) { logFile = tempList[tempList.Count - 1]; } else { // no log files so use default logFile = GenerateNewLogName(logFile); tempList.Add(logFile); } FileInfo logFileInfo = new FileInfo(logFile); // exit out if out of size or count if (!_job.LogFileOverWrite && logFileInfo.Exists && _job.LogFileMaxCount > 0 && tempList.Count >= _job.LogFileMaxCount && _job.LogFileMaxSize > 0 && logFileInfo.Length >= _job.LogFileMaxSizeBytes) { _cdfMonitor.EtwTraceStop(); _cdfMonitor.LogOutput("DEBUG:ManageSequentialLogs:reached max logfile size limit/count. quitting"); CDFMonitor.CloseCurrentSessionEvent.Set(); return(false); } DisableLogStream(); // We have complete logs list so now if logfilename doesnt exist, set and exit // File exists and has no more room if (FileManager.FileInUse(logFile) || (_job.LogFileMaxSize > 0 && logFileInfo.Exists && logFileInfo.Length >= _job.LogFileMaxSizeBytes)) { if (_job.LogFileMaxCount > 0 && tempList.Count >= _job.LogFileMaxCount) { // Delete oldest and generate new name FileManager.DeleteFile(tempList[0]); tempList.Remove(tempList[0]); } logFile = GenerateNewLogName(logFile); tempList.Add(logFile); } CurrentLogFileSize = File.Exists(logFile) ? new FileInfo(logFile).Length : 0; Logs = tempList.ToArray(); bool retval = SetLogFileName(logFile); LoggingIsEnabled = true; _job.Enabled = true; if (LogFileServerEvt != null) { LogFileServerEvt.Set(); } return(retval); } }