我需要从文件中读取一个时间戳,然后回顾过去 30 分钟,看看是否显示了关键字“CM failed”。这是一个日志文件,即使在应用程序运行时也会不断更新。有任何想法吗?下面提供的代码确实回顾了过去 30 年,但我不确定它到底在看什么时间。
TimeSpan ts = TimeSpan.FromMinutes(30);
//fake file which is opened using Notepad++
string temp = @"C:\Temp\efilelog.txt";
private void Form1_Load(object sender, EventArgs e)
{
string str = File.ReadAllText(temp);
Regex reg = new Regex("CM failed" + DateTime.Now.Subtract(ts));
Match mat = reg.Match(str);
// Get the creation time of a well-known directory.
//DateTime dt = File.GetLastWriteTime(file);
//Console.WriteLine("The last write time for this file was {0}.", dt, ts);
if (mat.Success)
{
//send email which I already have functional
}
this.Close();
}
}