SL本地写日志
SL是一个客服端,不允许操作用户的电脑上的文件。但是可以操作 我的文档(My Documents)的文件
所以为了程序员方便调试! 在本地大日志,都把日志打印在我的文档下面的文件夹中
第一步:所以我们要配置silverlight项目程序

第二步:

这样都可以在程序中打印出日志
打印日志的方法
StreamWriter sw;
System.Diagnostics.Debug.WriteLine("11111");
string strErrLog = @"C:\Users\Administrator\Music\gErr.txt";
lock (strErrLog)//给线程进行枷锁
if (File.Exists(strErrLog))
{
FileInfo oFile = new FileInfo(strErrLog);
if (oFile.Length > 1024000)
{
oFile.Delete();
}
}
if (File.Exists(strErrLog))
{
sw = File.AppendText(strErrLog);
}
else
{
sw = File.CreateText(strErrLog);
}
string strDate = "时间:" + string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
string strErrMoudle = "模块:" + strErrMod;
string strErrDescOut = "原因:" + strErrDesc;
sw.WriteLine(strDate);
sw.WriteLine(strErrMoudle);
sw.WriteLine(strErrDescOut);
sw.WriteLine("===================================================================");
sw.Flush();
sw.Close();

浙公网安备 33010602011771号