C#:将错误信息写到txt文件中

          

//以连库为例

          SqlConnection con;

          try
        {
            con = new SqlConnection();
            con.Open();
            return con;
        }
        catch(Exception e)
        {

               //如果不存在 error文件夹就创建一个
            if (!Directory.Exists(@"~/error"))
            {
                Directory.CreateDirectory(@"~/error");
            }

           //将错误信息追加写入文件
            File.AppendAllText(@"~/error/error.txt", e.Message+"第n行错误\r\n");

           
        }

posted on 2008-09-15 17:28  VictorShan  阅读(325)  评论(0)    收藏  举报

导航