zoukankan      html  css  js  c++  java
  • 设置Log记录

    static void Log(string str, Object o)
            {
                String message = String.Empty;
                if (o.GetType() == typeof(Exception))
                {
                    message = ((Exception)o).Message;
                }
                else
                {
                    message = o.ToString();
                }
    
                string strPath = @"C:Mentoring";
                string fileName = "MentoringMatchLog";
                //得到物理路径中的文件
                string newPath = Path.Combine(strPath);
                if (!Directory.Exists(newPath)) //若文件夹不存在则新建文件夹   
                {
                    Directory.CreateDirectory(newPath); //新建文件夹  
                }
    
                if (System.IO.File.Exists(strPath + "\" + fileName + ".txt"))
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(strPath + "\" + fileName + ".txt", true))
                    {
                        sw.WriteLine("DateTime:" + DateTime.Now + " ; " + str + ":" + message);
                        sw.Close();
                    }
                }
                else
                {
                    System.IO.File.Create(strPath + "\" + fileName + ".txt").Close();
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(strPath + "\" + fileName + ".txt", true))
                    {
                        sw.WriteLine("DateTime:" + DateTime.Now + " ; " + str + ":" + message);
                        sw.Close();
                    }
                }
    
            }
  • 相关阅读:
    迭代器概念与traits编程技法
    C++模板的特化与偏特化
    c++ operator关键字
    cookie-小总结吧
    ping
    git
    setTimeout()基础/setInterval()基础
    SASS
    命令行编译sass
    sublime添加sass编译
  • 原文地址:https://www.cnblogs.com/learning-life/p/10722920.html
Copyright © 2011-2022 走看看