Download the values before writing them to disk.
Complete the recording only after the transaction is completed.
Something like that:
StringBuilder builder = new StringBuilder(); // do transaction step 1 builder.Append("Transaction step 1" + environment.NewLine); // or however you add a line to you log // step 2 builder.Append("Transaction step 2" + environment.NewLine); //... // step 50 builder.Append("Transaction step 50" + environment.NewLine); // now write to the file File.WriteAllText(@"C:\log.txt", builder.ToString());
You can add some processing if there is an error at any stage for logging.
You can also use some open source tool like log4net: http://logging.apache.org/log4net/ .
source share