Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Problem in reading a log file

Problem in reading a log file

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m samar
    wrote on last edited by
    #1

    Hi every one I have a log file that continually is filling by a application. How can I read the log file? I tried

    _StreamReader tr=new StreamReader("d:\\\\theLogFile.txt");
            MessageBox.Show(tr.ReadLine());_
    

    but got "The process cannot access the file because it is being used by another process." error. help please? thanks.

    K L 2 Replies Last reply
    0
    • M m samar

      Hi every one I have a log file that continually is filling by a application. How can I read the log file? I tried

      _StreamReader tr=new StreamReader("d:\\\\theLogFile.txt");
              MessageBox.Show(tr.ReadLine());_
      

      but got "The process cannot access the file because it is being used by another process." error. help please? thanks.

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      Fundamentally, something has the file open for it's exclusive use. Most likely, whatever is writing to the log has it locked. Another possibility is that, if you have the log open in notepad / word/ other text editor it locked by this.

      1 Reply Last reply
      0
      • M m samar

        Hi every one I have a log file that continually is filling by a application. How can I read the log file? I tried

        _StreamReader tr=new StreamReader("d:\\\\theLogFile.txt");
                MessageBox.Show(tr.ReadLine());_
        

        but got "The process cannot access the file because it is being used by another process." error. help please? thanks.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, if your app-under-test is logging to a file by opening a file once, and writing to it, and finally closing it upon exit, then no other app can read that file while the AUT is running. What I often do is keep the logfile closed and add a line of text to it using

        public void log(string s) {
        File.AppendAllText(logfileName, s+Environment.NewLine);
        }

        And for apps that run for several hours, I switch logfiles regularly, so each file remains limited in size, can be deleted when no longer useful, can be copied/emailed to another location, etc. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        M 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, if your app-under-test is logging to a file by opening a file once, and writing to it, and finally closing it upon exit, then no other app can read that file while the AUT is running. What I often do is keep the logfile closed and add a line of text to it using

          public void log(string s) {
          File.AppendAllText(logfileName, s+Environment.NewLine);
          }

          And for apps that run for several hours, I switch logfiles regularly, so each file remains limited in size, can be deleted when no longer useful, can be copied/emailed to another location, etc. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          M Offline
          M Offline
          m samar
          wrote on last edited by
          #4

          Uufortunately the logger application does not release the log file during running... anyway... thank you for your answers

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups