예제 #1
0
 public static void Log(string message)
 {
     lock (FileFolderHelper.LogFilepath)
     {
         StreamWriter writer = null;
         FileStream   file   = null;
         try
         {
             FileFolderHelper.CheckAndCreateFile(FileFolderHelper.LogFilepath);
             file   = new FileStream(FileFolderHelper.LogFilepath, FileMode.Append);
             writer = new StreamWriter(file);
             writer.WriteLine(DateTime.Now.ToString("HH:mm:ss.ms") + " " + message);
         }
         catch
         {
         }
         finally
         {
             writer?.Close();
             file?.Close();
             writer = null;
             file   = null;
         }
     }
 }
예제 #2
0
 public static void Serialize <TObject>(TObject obj, string filePath)
 {
     try
     {
         FileFolderHelper.CheckAndCreateFile(filePath);
         var formatter = new BinaryFormatter();
         using (var stream = new FileStream(filePath, FileMode.Create))
         {
             formatter.Serialize(stream, obj);
         }
     }
     catch (Exception ex)
     {
         Logger.Log($"Failed to serialize data to file {filePath}", ex);
         throw;
     }
 }