我正在使用此帖IIS 7 Log Request Body中的代码,以便我可以看到人们尝试访问我的网站时发生的情况。
protected void Application_BeginRequest(Object sender, EventArgs e)
{
var uniqueid = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);
var logfile = String.Format("C:\\logs\\{0}.txt", uniqueid);
Request.SaveAs(logfile, true);
}
当它运行时,我收到此消息:
The process cannot access the file 'C:\logs\635256490792288683.txt' because it is being used by another process.
每隔一段时间,人们就会对网站没有任何回应,我迫切需要了解发生了什么。
知道如何解决这个问题吗?
答案 0 :(得分:1)
DateTime.Now
的分辨率不足以满足您的要求。要快速修复,您可以使用new Guid().ToString();
但不要在生产中执行此操作,这会严重损害您的网站性能。