例子,c#生成日志并保存到文件。
 
复制代码 代码示例:
public static void AppendTextToFile(string fullname, string msg)
{ 
try 
{
 using (StreamWriter sw = File.AppendText(fullname))
 { 
    sw.WriteLine(msg); 
    sw.Dispose(); } } 
    catch (Exception ex) 
    {
    throw ex; }
    }
    private void button1_Click(object sender, EventArgs e)
    {
      AppendTextToFile("d:carlog.txt", "aaa");
 }