以流的形式完成日志记录

public static string statistical_data = "统计数据信息.txt";
 //    List<string> list = new List<string>();
 //    list.Add("标题=" + Title_null_num.ToString() + "RowId=" + idr["RowId"].ToString());
//    list.Add("内容=" + FullContent_null_num.ToString() + "RowId=" + idr["RowId"].ToString());
 //    list.Add("发布日期=" + PromulgateDate_null_num.ToString() + "RowId=" + idr["RowId"].ToString());
//    list.Add("发文字号=" + PromulgateWritNumber_null_num.ToString() + "RowId=" + idr["RowId"].ToString());
 //StatuteTestWriteLog.WriteLog_Append(statistical_data, list);//记录日志
 //StatuteTestWriteLog.WriteLog_OpenOrCreate(statistical_data, list);//记录日志
 
public class StatuteTestWriteLog
    {
        public static void WriteLog_Append(string LogName, List<string> list)
        {
            using (FileStream fst2 = new FileStream(LogName, FileMode.Append))
            {
                using (System.IO.StreamWriter _writer = new System.IO.StreamWriter(fst2))
                {
                    foreach (string str in list)
                    {
                        _writer.WriteLine(str);
                    }
                    _writer.Close();
                    fst2.Close();
                }
            }
        }
        public static void WriteLog_OpenOrCreate(string LogName, List<string> list)
        {
            using (FileStream fst2 = new FileStream(LogName, FileMode.OpenOrCreate))
            {
                using (System.IO.StreamWriter _writer = new System.IO.StreamWriter(fst2))
                {
                    foreach (string str in list)
                    {
                        _writer.WriteLine(str);
                    }
                    _writer.Close();
                    fst2.Close();
                }
            }
        }
    }
posted @ 2011-05-11 13:14  石 磊  阅读(364)  评论(0编辑  收藏  举报