stackoverflow进入不了_关于System.StackOverflowException的问题

///

/// 文本记录

///

/// 文本信息

/// 1错误日志 2运行日志

public static void LogText(string msg,int type)

{

lock (obj)

{

System.Text.StringBuilder str = new System.Text.StringBuilder();

str.Append(DateTime.Now.ToString() + ":");

str.Append(msg);

str.Append("\n");

if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Log"))

Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Log");

string FilePath;

if (type == 1)

FilePath = AppDomain.CurrentDomain.BaseDirectory + "Log\\err_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";

else if(type==2)

FilePath = AppDomain.CurrentDomain.BaseDirectory + "Log\\run_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";

else

FilePath = AppDomain.CurrentDomain.BaseDirectory + "Log\\cf_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";

System.IO.StreamWriter sw = null;

try

{

if (!System.IO.File.Exists(FilePath))

{

System.IO.FileStream fs = System.IO.File.Create(FilePath);

fs.Close();

}

sw = new System.IO.StreamWriter(FilePath, true, System.Text.Encoding.Default);

sw.Write(str.ToString());

}

catch (Exception ex)

{

}

finally

{

if (sw != null)

sw.Close();

}

}

}

一个写日志的方法。软件运行久了就会在“sw =newSystem.IO.StreamWriter(FilePath,true, System.Text.Encoding.Default);”这句报System.StackOverflowException的异常。

System.StackOverflowException往往是出现无限制的递归导致的,函数调用层次过多导致栈溢出。而该代码应该没有递归之类的。

请达人帮忙分析一下,该代码问题所在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值