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();
                    }
                }
    
            }
  • 相关阅读:
    算法提高 身份证号码升级
    枚举排列
    排列数
    算法训练 K好数
    算法训练 前缀表达式
    算法训练 区间k大数查询
    最大最小公倍数
    Anagrams问题
    Uiautomator 2.0
    Uiautomator 2.0
  • 原文地址:https://www.cnblogs.com/learning-life/p/10722920.html
Copyright © 2011-2022 走看看