我正在尝试读取文本文件并将其显示在 plage 上。这就是我所做的。但我收到错误
该进程无法访问文件“D:\wwwroot\TestProject\Logs\TestLog.log”,因为它正被另一个进程使用。
控制器代码
Array LogFileData = null;
var logFileNameWithPath = Server.MapPath("D:\wwwroot\TestProject\Logs\TestLog.log");
if (System.IO.File.Exists(logFileNameWithPath))
{
LogFileData = System.IO.File.ReadAllLines(logFileNameWithPath);
}
ViewBag.logFileContent = LogFileData;
查看代码
@if (ViewBag.logFileContent != null)
{
foreach (string dataLine in ViewBag.logFileContent)
{
@dataLine
<br />
}
}
日志文件由服务创建和使用。我的代码在我停止服务时有效。但我并没有试图在服务写入文件的同时专门写入文件。事实上,我正试图在服务没有写入它的时候阅读。关于如何解决这个问题的任何建议?谢谢。