zoukankan      html  css  js  c++  java
  • .net 本地日志的添加

     1 /// <summary>  
     2 /// 写入日志到文本文件  
     3 /// </summary>  
     4 /// <param name="userName">用户名称</param>  
     5 /// <param name="action">动作</param>  
     6 /// <param name="content">日志内容</param>  
     7 /// <param name="result">操作结果或报错信息</param>  
     8 /// <param name="msg">报错信息</param>  
     9 public static void WriteTextLog(string userName, string action, string content, string result, string msg)
    10 {
    11     try
    12     {
    13         DateTime time = DateTime.Now;
    14         string path = AppDomain.CurrentDomain.BaseDirectory + "/Log/" + time.ToString("yyyy-MM") + "/";
    15         if (!Directory.Exists(path))
    16             Directory.CreateDirectory(path);
    17 
    18         string fileFullPath = path + time.ToString("yyyy-MM-dd") + ".txt";
    19         StringBuilder str = new StringBuilder();
    20         str.Append("用户:  " + userName + "
    ");
    21         str.Append("时间:  " + time.ToString() + "
    ");
    22         str.Append("类型:  " + action + "
    ");
    23         str.Append("内容:  " + content + "
    ");
    24         str.Append("结果:  " + result + "
    ");
    25         str.Append("备注:  " + msg + "
    ");
    26         str.Append("-----------------------------------------------------------
    
    ");
    27         StreamWriter sw;
    28         if (!File.Exists(fileFullPath))
    29         {
    30             sw = File.CreateText(fileFullPath);
    31         }
    32         else
    33         {
    34             sw = File.AppendText(fileFullPath);
    35         }
    36         sw.WriteLine(str.ToString());
    37         sw.Close();
    38     }
    39     catch (Exception)
    40     {
    41                 
    42     }
    43}
  • 相关阅读:
    匿名方法
    优化从 App.config 读取配置文件
    显示(explicit )与隐式(implicit)转换操作符
    ( 转 ) 聊一聊C#的Equals()和GetHashCode()方法
    协变和逆变
    html frameset的介绍
    html <frame>标签使用
    html <table>标签信息
    html 列表相关信息
    html <form>相关表单
  • 原文地址:https://www.cnblogs.com/xujunbao/p/8340388.html
Copyright © 2011-2022 走看看