Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*DHB++ 10/26/2010 WPL013419 - Improved upgrader logging
- /// <summary>
- /// Creates the new log file if needed.
- /// </summary>
- /// <param name="maxDebugFileSize">Max size of the debug file.</param>
- public static void CreateNewLogFileIfNeeded(double maxDebugFileSize)
- {
- // Don't proceed if the max size is zero (no limit) or if the
- // debug file doesn't exist, or we don't know the location of it...
- if (maxDebugFileSize > 0.0 && !string.IsNullOrEmpty(m_sDebugFile) && File.Exists(m_sDebugFile))
- {
- // vars to keep track of actions
- bool bBackupFileExisted = false;
- bool bBackupDeleted = false;
- // setup the backup file path and file info
- string sBackupFilePath = m_sDebugFile.Substring(0, m_sDebugFile.LastIndexOf('.')) + BACKUP_EXTENSION;
- FileInfo oCurrentLogFileInfo = new FileInfo(m_sDebugFile);
- // check if we need to do the update yet.
- if (((double)oCurrentLogFileInfo.Length * BYTES_IN_MEGABYTE) >= maxDebugFileSize)
- {
- // the backup file exists.
- if (File.Exists(sBackupFilePath))
- {
- bBackupFileExisted = true;
- // try to delete the file. If it succeeded, mark that it did. If it didn't, log the failure.
- try
- {
- File.Delete(sBackupFilePath);
- bBackupDeleted = true;
- }
- catch
- {
- LogInfo("Deletion of backup log file " + sBackupFilePath + " could not occur. It was readonly, locked by another process, or upgrader did not have permissions to delete this file.");
- }
- }
- // don't try to make the backup, and delete the current, if we couldn't delete the backup.
- // unless, of course, the backup didn't exist to be deleted.
- if (bBackupDeleted || !bBackupFileExisted)
- {
- // try to move the "current" log file to be the backup. If we move it, it'll
- // just be created later, so we don't need to re-create it, or copy instead.
- try
- {
- oCurrentLogFileInfo.MoveTo(sBackupFilePath);
- }
- catch
- {
- LogInfo("Creation of backup log file " + sBackupFilePath + " could not occur. It's possible that upgrader did not have permissions to create this file.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement