生成txt日志操作文件 Alec

项目中经常会用到需要txt文本记录操作、异常、成功等信息的情况,这里是一个小例子。

代码如下:

String txtLogPath = "D:\\错误日志.txt";
                using (StreamWriter swlog = new StreamWriter(txtLogPath, true, System.Text.Encoding.Default))
                {
                    swlog.WriteLine("主题:发布博客园随笔" );
                    swlog.WriteLine("时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    swlog.WriteLine("错误原因:随笔中含有不健康文字,服务器无法承受,频临崩溃!!");
                    swlog.WriteLine();//每条错误日志之间用空行隔开
                    swlog.Close();
                }
原文地址:https://www.cnblogs.com/yinluhui0229/p/2620473.html