服务程序如何跟踪调试

toball 2004-11-10 01:44:14
高手请进服务程序如何调试
...全文
86 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
friendsyu 2004-11-22
  • 打赏
  • 举报
回复
顶!!
windinwing 2004-11-21
  • 打赏
  • 举报
回复
有点麻烦,不过可以自已标记一个debug模式,把出错信息写到一个文件里
public class Core
{
#region 写入日志

/// <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

在catch块里
if(debug)
{
Core.WriteLog(文件名,出错信息);

}
friendsyu 2004-11-21
  • 打赏
  • 举报
回复
up

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧