public static void Serialize <T>(T obj, string filePath)
        {
            FileFolderHelper.CheckAndCreateFile(filePath);

            using (var stream = new FileStream(filePath, FileMode.Create))
                new BinaryFormatter().Serialize(stream, obj);
        }
Beispiel #2
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
                {
                    // ignored
                }
                finally
                {
                    writer?.Close();
                    file?.Close();
                }
            }
        }