0
我指示進程的標準輸出/錯誤,並將其存儲在一個字符串中,我登錄到一個文件。字符串太小,無法存儲進程的標準輸出
我注意到並非所有的標準輸出都存儲在文本文件中,所以我必須達到字符串的大小限制。
有誰知道有助於解決這個問題的替代方案嗎?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Logging
{
class Logger
{
private FileStream file = null;
private StreamWriter writer = null;
public Logger(string _path)
{
if (!File.Exists(_path)) File.Create(_path).Dispose();
file = new FileStream(_path, FileMode.Append, FileAccess.Write, FileShare.Write);
writer = new StreamWriter(file);
}
public void Log(string _text)
{
Console.WriteLine(_text);
using (file)
{
writer.WriteLine("[" + DateTime.Now + "] : " + _text);
}
}
}
}
沒有爲字符串不理智的大小限制。 (你的過程不是寫2GB的輸出) – SLaks
在我看來,這可能是你沒有沖洗這個作者。 –
我的心理調試技巧告訴我,你正在吞噬所有的異常而不讀取它們。不要這樣做。 – SLaks