写txt格式日志,偶发情况下所有的日志内容写到文件里都是nul,没抛异常,但是软件会在一段时间后闪退
private static void WriteData(string content, string fullPath, bool needDateTime = true){
try
{
lock (lockObj)
{
if (string.IsNullOrEmpty(fullPath))
{
return;
}
if (!Directory.Exists(Path.GetDirectoryName(fullPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
}
using (var sw = new StreamWriter(fullPath, true, Encoding.Default))
{
//StreamWriter sw = File.AppendText(fullPath);
sw.WriteLine((needDateTime ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff ") : "") + content);
sw.Close();
sw.Dispose();
}
}
}
catch (Exception e)
{
WriteExcept("WriteData Err:" + e + ",content:" + content);
if (GetHardDiskFreeSpace(Path.GetPathRoot(AppDomain.CurrentDomain.BaseDirectory)) < 1 &&
!e.Message.Contains("used by"))
{
IsDiskSpaceFull = true;
MessageBox.Show("写入日志异常," + e.Message + ",content:" + content);
}
}
}
有大佬遇到过这个问题吗?
回答
查一下操作系统日志,看看有没有蛛丝马迹
以上是 写txt格式日志,偶发情况下所有的日志内容写到文件里都是nul,没抛异常,但是软件会在一段时间后闪退 的全部内容, 来源链接: utcz.com/a/60511.html