locked
Problem with logging exception into txt file RRS feed

  • Question

  • User1594680833 posted

    Hi

    I am trying to log all my exception  in a txt file on the server. and i am creating a log file for each day,

    My problem is i am unable to store two logs of same day in same file,

    It always replaces the previous content.

    Thanks

     FileStream fs = new FileStream("z:\\Connection_log" + DateTime.Today.ToString("dd-MM-yyyy") + ".txt", FileMode.OpenOrCreate, FileAccess.Write); 
                    System.IO.StreamWriter sw = new StreamWriter(fs); 
                    try 
                    {
                     string logLine = System.String.Format( 
                     "{0:G}: {1}.", System.DateTime.Now, msg); 
                     sw.WriteLine("\r\nLog Entry : "); 
                     sw.WriteLine(logLine);
                     }
                    finally 
                    {
                    sw.Close();
                     }


     

      

    Thursday, February 4, 2010 7:56 AM

Answers