Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I created a LOG file (ErrorLog) that I use to output/trace information from my application, problem is the I want to be able to read the file as things progress.

Given the way I coded it (see below) the information I write into the file is only saved afer I do the .CLOSE (meaning that if I open the .log file there is nothing written until I do the .close)

I would much rather be able to read the .log file while the application is running to see if anything is generated... (I don't want to have to CLOSE the file to see what was written to it).

 


StreamWriter ErrorLog = new StreamWriter(File.Open("App.log", FileMode.Append, FileAccess.Write, FileShare.ReadWrite));
string errMessage = DateTime.Now + ": " + sMessage;
ErrorLog.WriteLine(errMessage);
...
... do some work ...
...
ErrorLog.Close();
[/Code]

 

Any helps/hints/clues would be appreciated - I know there is a way I just can't recall how to get it to work.

Thanks,

Posted
why not use .Net eventlog class

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • Administrators
Posted

Personally I would agree with Joe Mamma on this and would use the built in eventlog support - much better for administrators as your app will log to the same place as all other applications, plus there are standard tools for viewing, searching etc.

Failing that have you tried calling .Flush() and seeing if that makes a difference?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...