zoukankan      html  css  js  c++  java
  • 自定义日志

    适用于小型项目,自定义日志方法如下
        
     1     public static void WriteLogs(string content)
     2         {
     3             string path = AppDomain.CurrentDomain.BaseDirectory;
     4             string LogName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace.Split('.')[0];
     5             string[] sArray = path.Split(new string[] { LogName }, StringSplitOptions.RemoveEmptyEntries);
     6             string aa = sArray[0] + "\" + LogName + "Log\";
     7             path = aa;
     8             if (!string.IsNullOrEmpty(path))
     9             {
    10                 if (!Directory.Exists(path))
    11                 {
    12                     Directory.CreateDirectory(path);
    13                 }
    14                 path = path + "\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//
    15                 if (!File.Exists(path))
    16                 {
    17                     FileStream fs = File.Create(path);
    18                     fs.Close();
    19                 }
    20                 if (File.Exists(path))
    21                 {
    22                     StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default);
    23                     sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "----" + content + "
    ");
    24                     sw.Close();
    25                 }
    26             }
    27         }
  • 相关阅读:
    [转]zookeeper-端口说明
    ACM-ICPC(9/26)
    ACM-ICPC(9/25)
    Linux的文件权限与目录配置
    Uva 11468 AC自动机或运算
    Uva 11922 Splay
    HDU 6214 最小割边
    Uva 10559 消除方块
    HDU 6194 后缀数组
    Uva 11491 暴力贪心
  • 原文地址:https://www.cnblogs.com/ywkcode/p/10896262.html
Copyright © 2011-2022 走看看