CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    May 2008
    Posts
    66

    [RESOLVED]Using textwriter

    Hi all!

    I code this function in order to create a log of my app.

    My app calls this function every something wrong occurs. The file is created if it does not exist before.

    The problem is that when I open the file, using the windows explorer, it is blank. So, any information was written in it. But, the function was called many times, as I could see debugging the app (the logMessage parameter is not empty anytime).

    What is it wrong?

    Code:
            public void Log (String logMessage, String w) {
                TextWriter textWriter = new StringWriter();
                using (TextWriter streamWriter = new StreamWriter(w)) {
    
                    textWriter.Write("\r\nLog Entry : ");
                    textWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
                        DateTime.Now.ToLongDateString());
                    textWriter.WriteLine("  :");
                    textWriter.WriteLine("  :{0}", logMessage);
                    textWriter.WriteLine("-------------------------------");
                    // Update the underlying file.
                    textWriter.Flush();
                    textWriter.Close();
                }
            }
    Thank you in advance.
    Last edited by gborges; August 6th, 2008 at 05:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured