• 日志记录到记事本


    记录日志是常用的,以下是一个在指定目录下面按天穿件日志文件的公共类:

     1 /// <summary>
     2     /// 公用日志
     3     /// </summary>
     4     public class Log
     5     {
     6         private static string path = Environment.CurrentDirectory + @"/logs";
     7 
     8         public static void WriteLog(string functionName, Dictionary<string, string> param,double seconds)
     9         {
    10             if (!Directory.Exists(path))//如果日志目录不存在就创建
    11             {
    12                 Directory.CreateDirectory(path);
    13             }
    14             string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");//获取当前系统时间
    15             string filename = path + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";//用日期对日志文件命名
    16                                                                                         //创建或打开日志文件,向日志文件末尾追加记录
    17             StreamWriter mySw = File.AppendText(filename);
    18 
    19             //向日志文件写入内容
    20             StringBuilder write_content = new StringBuilder("/**************************************/
    记录日志时间:" + time + "
    执行方法:" + functionName + "
    执行耗时:" + seconds+"");
    21             foreach (string item in param.Keys)
    22             {
    23                 write_content.Append(string.Format("{0}:{1}
    ",item, param[item]));
    24             }
    25             write_content.Append("/**************************************/
    ");
    26             mySw.WriteLine(write_content);
    27 
    28             //关闭日志文件
    29             mySw.Close();
    30         }
    31     }
  • 相关阅读:
    python 类定义 继承
    BAYSY2 的LVDS引脚 笔记
    Fedora20-32bit cross-compiling arm-linux-gcc4.3.2
    以冒泡排序为例--malloc/free 重定向stdin stdout
    笔记:程序内存管理 .bss .data .rodata .text stack heap
    第一章 数值和码制
    《将博客搬至CSDN》
    Servlet 3.0 新特性
    java Servlet接口及应用
    C语言输出单个汉字字符
  • 原文地址:https://www.cnblogs.com/CarlBlogs/p/7404981.html
Copyright © 2020-2023  润新知