Browse Source

添加本地日志记录

章政 5 năm trước cách đây
mục cha
commit
82e3e3d4d9
1 tập tin đã thay đổi với 12 bổ sung0 xóa
  1. 12 0
      FileWatcher/Form1.cs

+ 12 - 0
FileWatcher/Form1.cs

@@ -42,6 +42,7 @@ namespace FileWatcher
                     if (File.Exists(FullName))
                     {
                         richTextBox1.AppendText(DateTime.Now.ToString("yyyy/MM/dd h:mm:ss.fff") + e.FullPath + "\n");
+                        DoLog(FullName);
                     }
                     else
                     {
@@ -70,6 +71,17 @@ namespace FileWatcher
             }
         }
 
+        public  void DoLog(string Message)
+        {
+            try
+            {
+                StreamWriter sw = File.AppendText(DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
+                sw.WriteLine("\n【时间】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Message + "\n");
+                sw.Close();
+            }
+            catch (Exception) { }
+        }
+
         /// <summary>
         /// 私有变量
         /// </summary>