12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System;
- using System.IO;
- using System.Windows.Forms;
- namespace PaintDotNet.Camera
- {
- public class Logs
- {
- private static string m_filePath = Application.StartupPath + "\\CameraLogs\\";
- private static void chkFile()
- {
- if (!Directory.Exists(m_filePath))
- {
- Directory.CreateDirectory(m_filePath); //不存在就创建目录
- }
- }
- public static void Write(string str)
- {
- try
- {
- #if DEBUG
- str = DateTime.Now.ToString("HH:mm:ss:fff") + ":" + str;
- chkFile();
- StreamWriter sw = File.AppendText(m_filePath + DateTime.Now.ToString("log") + ".txt");
- //开始写入
- sw.WriteLine(str);
- //清空缓冲区
- sw.Flush();
- //关闭流
- sw.Close();
- #endif
- }
- catch (Exception)
- {
- }
- }
- public static void Clear()
- {
- try
- {
- File.Delete(m_filePath + DateTime.Now.ToString("log") + ".txt");
- }
- catch (Exception) { }
- }
- }
- }
|