C# streamwriter 不会覆盖更多信息

C# streamwriter does not overwrite futher information

我正在为我的学校做一个计算器项目。

我在将我的操作覆盖到文本文档时遇到问题,通常我的文本文件中应该有这个:

1|peter|DESKTOP-P6IL7VV|19/11/2017 11:38:11  ==>  5 x 5=25       
2|peter|DESKTOP-P6IL7VV|19/11/2017 11:38:15  ==>  25 + 3=28      
3|peter|DESKTOP-P6IL7VV|19/11/2017 11:38:27  ==>  28 / 2=14      
4|peter|DESKTOP-P6IL7VV|19/11/2017 11:38:31  ==>  14 + 6=20      
5|peter|DESKTOP-P6IL7VV|19/11/2017 11:38:35  ==>  20 - 20=0                
(example from my teacher)

但是每次我写东西,它删除第一行,只覆盖最后一个操作,我需要每次点击结果按钮,它按数字顺序覆盖到我的文件

这是我的编码:

private void result_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            result();
        }
        catch (Exception exc)
        {
            txtIngave.Text = "Error!";
        }
        try
        {
            if (!txtResultaat.Text.Equals(string.Empty) && btnLog.IsChecked 
            == true)
            {
                int i = 1;
                using (StreamWriter myOper = new 
     StreamWriter(@"C:\Users\Ach\Documents\Visual Studio 
      2017\Projects\TaakCalculator\log\log.txt"))
                {
                   myOper.WriteLine(i.ToString() + " | " + "Achraf | " + System.Environment.MachineName + " | " + DateTime.Now.ToLongTimeString() + " | ==> " + txtResultaat.Text);
                }
                i++;

            }
        }
        catch (Exception ex)
        {

            MessageBox.Show("Loser");
        }
    }

试试

StreamWriter(string path, bool append) 

构造函数,参数 appendtrue

来自documentation

append

true to append data to the file; false to overwrite the file. If the specified file does not exist, this parameter has no effect, and the constructor creates a new file.