我已經寫了下面的代碼:FileStream.Write不寫什麼
public static class PLog
{
private static FileStream logFileStream;
private static string logFilePath;
public static void Initialize()
{
logFilePath = PSettings.IO.dirLogs + "log_" + DateTime.Now.ToString("ddMMyy_HHmmss") + ".txt";
if (!Directory.Exists(PSettings.IO.dirLogs)) Directory.CreateDirectory(PSettings.IO.dirLogs);
logFileStream = new FileStream(logFilePath, FileMode.Create);
}
public static void WriteLine(string text)
{
byte[] textArray = Encoding.ASCII.GetBytes("[" + DateTime.Now.ToString("dd.MM.yyyy - HH:mm:ss") + "] " + text + "\n");
logFileStream.Write(textArray, 0, textArray.Length);
}
public static void Close()
{
logFileStream.Close();
}
}
但是,當我這樣稱呼它,它不會寫入任何文件:
PLog.Initialize();
PLog.WriteLine("test");
PLog.Close();
該文件已創建,但它的大小爲0字節。
你有沒有叫Close();方法呢? –
如果你的問題已經解決,那麼請馬克解決它的anwser。 – Maximc