http://www.ondotnet.com/pub/a/dotnet/2003/09/02/debuggingsvcs.html

解决方案 »

  1.   

    都你个笨点的方法,不过很好用
    调式的时候WriteLog一次,在打开记事本看看就是
    运行无误后在删掉#region 写入日志 #region function WriteLog(fileName,text) /// <summary>
    /// 写入日志
    /// </summary>
    /// <param name="fileName">写入日志的文件名和路径</param>
    /// <param name="text">日志文本</param>
    public static void WriteLog(string fileName,string text)
    {
    try
    {
    // 检查目录路径
    if(fileName.IndexOf("\\") > -1)
    {
    string dirPath = fileName.Substring(0,fileName.LastIndexOf("\\"));
    // 检查目录是否存在,如果不存在创建它
    if(!Directory.Exists(dirPath))
    {
    Directory.CreateDirectory(dirPath);
    }
    } using(FileStream fs = new FileStream(fileName,FileMode.OpenOrCreate, FileAccess.Write))
      {
    StreamWriter w = new StreamWriter(fs);     
    w.BaseStream.Seek(0, SeekOrigin.End);      
    w.Write(text + "\r\n");
    w.Flush(); 
    }
    }
    catch
    {
    }
    } #endregion #endregion