• 写错误日志


    public void WriteMessage(string filename, string message, string method)
            {
                string path = GetAssemblyPath() + @"\errorlog.txt";
                FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.BaseStream.Seek(0, SeekOrigin.End);
                    StringBuilder sb = new StringBuilder();
                    sb.Append("时间:");
                    sb.Append(DateTime.Now);
                    sb.Append("      文件:");
                    sb.Append(filename + "     ");
                    sb.Append("方法:" + method);
                    sb.Append("     内容:");
                    sb.Append(message);
                    sw.WriteLine(sb);
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                }
            }

    private string GetAssemblyPath()        

    {            

               string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;

               _CodeBase = _CodeBase.Substring(8, _CodeBase.Length - 8);    // 8是 file:// 的长度

               string[] arrSection = _CodeBase.Split(new char[] { '/' });

               string _FolderPath = "";           

               for (int i = 0; i < arrSection.Length - 1; i++)           

    {               

          _FolderPath += arrSection[i] + "/";      

    }

               return _FolderPath;    

    }

    工欲善其事,必先利其器。
  • 相关阅读:
    解决url传递过程中加号变空格的问题<转>
    windows下CEF3的关闭流程《转》
    mfc封装cef浏览器 关闭整个窗口程序得时候又重启mfc 应用的程序
    雷神免费资源
    LCA的 RMQ解法模版
    最新的js焦点图库
    whereis+whatis+man
    Anroid 手机助手 详细解析 概述(二)
    <c:forEach varStatus="status">中 varStatus的属性简介
    JBoss 系列四十九:JBoss 7/WildFly 中端口使用列表
  • 原文地址:https://www.cnblogs.com/zhangzhu/p/2817919.html
Copyright © 2020-2023  润新知