我在程序中使用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本身的线程的操作文件,引起不能读吗?要怎么解决?谢谢~~

解决方案 »

  1.   

    该文件被独占试下
    FileStream fs= new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);
      

  2.   

    我这么写的: FileStream fs = new FileStream(App.logPath, FileMode.Open, FileAccess.Read, FileShare.Read);还是在这句上报同样的错误。
      

  3.   

    应该是log4Net还在占用该文件吧
      

  4.   

    以前有过类似的问题,关于log4.net的webconfig配置中:
    是否加入这句话?如果没有加上,把以前的LOG文件都删掉重新生成再试试能不能读?
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>