zoukankan      html  css  js  c++  java
  • 随便写写之日志类

     1 using System;
     2 using System.IO;
     3 using System.Text;
     4 
     5 namespace CaptureData
     6 {
     7     /// <summary>
     8     /// 随便写的一个日志类哦
     9     /// </summary>
    10     public class Log
    11     {
    12         private static object obj = new object();
    13 
    14         public static void LogInfo(Object info)
    15         {
    16             var now = DateTime.Now;
    17             StringBuilder str = new StringBuilder();
    18             str.Append(now.ToString("yyyy-MM-dd HH:mm:ss:fff"));
    19             str.Append("
    ");
    20             str.Append(info);
    21             str.Append("
    ");
    22             write(str.ToString());
    23         }
    24 
    25         public static void LogInfoWithSession(string si, Object info)
    26         {
    27             var now = DateTime.Now;
    28             StringBuilder str = new StringBuilder();
    29             str.Append(now.ToString("yyyy-MM-dd HH:mm:ss:fff"));
    30             str.Append("----" + si);
    31             str.Append("
    ");
    32             str.Append(info);
    33             str.Append("
    
    ");
    34             write(str.ToString());
    35         }
    36         public static void write(string info)
    37         {
    38             var now = DateTime.Now;
    39             var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log");
    40             if (!Directory.Exists(path))
    41                 Directory.CreateDirectory(path);
    42             path = Path.Combine(path, now.ToString("yyyyMMddHH") + ".log");
    43             lock (typeof(Log))
    44             //lock (obj)
    45             {
    46                 File.AppendAllText(path, info);
    47             }
    48         }
    49     }
    50 }

    有追求,才有动力!

    向每一个软件工程师致敬!

    by wujf

    mail:921252375@qq.com

  • 相关阅读:
    java后台打开浏览器代码
    java国际化
    Struts2之action 之 感叹号 ! 动态方法调用
    ssh框架总结之action接收参数的三种方式
    电脑开机过程
    4.18quaternion rotation
    4.2
    "hello,world"lena
    bash 简介
    SCHEDULE
  • 原文地址:https://www.cnblogs.com/wujf/p/5688120.html
Copyright © 2011-2022 走看看