我在程序中使用log4net记录日志,现在想把日志在 程序中读出来。
代码: if (File.Exists(App.logPath))
{
StreamReader sr = new StreamReader(App.logPath);
string LogContent = sr.ReadToEnd();
sr.Close();
textBox_log.Text = LogContent;
}但执行到treamReader sr = new StreamReader(App.logPath);这一句时会出错:
The process cannot access the file 'log.txt' because it is being used by another process.这是因为log4net本身的线程的操作文件,引起不能读吗?要怎么解决?谢谢~~
代码: if (File.Exists(App.logPath))
{
StreamReader sr = new StreamReader(App.logPath);
string LogContent = sr.ReadToEnd();
sr.Close();
textBox_log.Text = LogContent;
}但执行到treamReader sr = new StreamReader(App.logPath);这一句时会出错:
The process cannot access the file 'log.txt' because it is being used by another process.这是因为log4net本身的线程的操作文件,引起不能读吗?要怎么解决?谢谢~~
FileStream fs= new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);
是否加入这句话?如果没有加上,把以前的LOG文件都删掉重新生成再试试能不能读?
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>