Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2021
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 KB | None | 0 0
  1.             // now either rename or copy (depends on copy setting)
  2.             if ((lrc.Copy) || (lrc.CopyTruncate))
  3.             {
  4.                 Logging.Log(Strings.Copying + " " + fi.FullName + Strings.To + rotate_path + rotate_name, Logging.LogType.Verbose);
  5.  
  6.                 if (cla.Debug == false)
  7.                 {
  8.                     try
  9.                     {
  10.                         if (bLogFileExists)
  11.                             File.Copy(fi.FullName, rotate_path + rotate_name, false);
  12.                     }
  13.                     catch (Exception e)
  14.                     {
  15.                         Logging.Log("Error copying file " + fi.FullName + " to " + rotate_path + rotate_name, Logging.LogType.Error);
  16.                         Logging.LogException(e);
  17.                         return;
  18.                     }
  19.  
  20.                     if (bLogFileExists)
  21.                     {
  22.                         File.SetCreationTime(rotate_path + rotate_name, DateTime.Now);
  23.                         File.SetLastAccessTime(rotate_path + rotate_name, DateTime.Now);
  24.                         File.SetLastWriteTime(rotate_path + rotate_name, DateTime.Now);
  25.                     }
  26.  
  27.                 }
  28.  
  29.                 if (lrc.CopyTruncate)
  30.                 {
  31.                     Logging.Log(Strings.TruncateLogFile, Logging.LogType.Verbose);
  32.  
  33.                     if (cla.Debug == false)
  34.                     {
  35.                         try
  36.                         {
  37.                             if (bLogFileExists)
  38.                             {
  39.                                 FileStream fs = new FileStream(fi.FullName, FileMode.Open);
  40.                                 fs.SetLength(0);
  41.                                 fs.Close();
  42.                             }
  43.                         }
  44.                         catch (Exception e)
  45.                         {
  46.                             Logging.Log("Error truncating file " + fi.FullName, Logging.LogType.Error);
  47.                             Logging.LogException(e);
  48.                             return;
  49.                         }
  50.                     }
  51.                 }
  52.  
  53.             }
  54.             else
  55.             {
  56.                 Logging.Log(Strings.Renaming + " " + fi.FullName + Strings.To + rotate_path + rotate_name, Logging.LogType.Verbose);
  57.  
  58.                 if (cla.Debug == false)
  59.                 {
  60.                     try
  61.                     {
  62.                         if (bLogFileExists)
  63.                             File.Move(fi.FullName, rotate_path + rotate_name);
  64.                     }
  65.                     catch (Exception e)
  66.                     {
  67.                         Logging.Log("Error renaming file " + fi.FullName + " to " + rotate_path + rotate_name, Logging.LogType.Error);
  68.                         Logging.LogException(e);
  69.                         return;
  70.                     }
  71.                 }
  72.  
  73.                 if (lrc.Create)
  74.                 {
  75.                     Logging.Log(Strings.CreateNewEmptyLogFile, Logging.LogType.Verbose);
  76.  
  77.                     if (cla.Debug == false)
  78.                     {
  79.                         try
  80.                         {
  81.                             FileStream fs = new FileStream(fi.FullName, FileMode.CreateNew);
  82.                             fs.SetLength(0);
  83.                             fs.Close();
  84.                         }
  85.                         catch (Exception e)
  86.                         {
  87.                             Logging.Log("Error creating new file " + fi.FullName, Logging.LogType.Error);
  88.                             Logging.LogException(e);
  89.                             return;
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement