Silverlight写错误日志

来源:互联网 发布:云计算的前景 编辑:程序博客网 时间:2024/04/30 11:54

说明是在基于网站的Silverlight项目
日志是记录在网站工程的目录,部署到IIS上之后,日志是下载IIS虚拟目录下的

参考代码


    public class MyLog
    {
        public static void WriteErrLog(string strErrMod, string strErrDesc)
        {
            StreamWriter sw;
            string strErrLog =
                System.AppDomain.CurrentDomain.BaseDirectory+ @"gErr.txt";   //获取写日志的路径
            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();
        }
    }