星空网 > 软件开发 > ASP.net

c#自定义日志记录

废话不多说,直接上代码:

 

很简单:将类复制到项目中,最后在配置文件上配置一下:logUrl即可。 默认保存在:项目/temp/log

 

/// <summary>  /// 日志类  /// </summary>  /// <remarks>Creator: v-lxh CreateTime: 2016/7/26 11:18:09</remarks>  /// <Description></Description>  public class Log  {    /// <summary>    /// 写入日志.    /// </summary>    /// <param name="strList">The STR list.</param>    /// <remarks>Creator: v-lxh CreateTime: 2016/7/26 11:18:09</remarks>    /// <Description></Description>    public static void WriteLog(params object[] strList)    {      //判断是否开启日志模式      //if (!LogModel) return;      if (strList.Count() == 0) return;      //日志文件路径      string strDicPath = "";      try      {        strDicPath = HttpContext.Current.Server.MapPath("~/temp/log/");        if (strDicPath == null || strDicPath == "")        {          strDicPath = System.Configuration.ConfigurationManager.AppSettings["logUrl"] + "/temp/log/";        }      }      catch (Exception e)      {        strDicPath = System.Configuration.ConfigurationManager.AppSettings["logUrl"] + "/temp/log/";      }      string strPath = strDicPath + string.Format("{0:yyyy年-MM月-dd日}", DateTime.Now) + "日志记录.txt";      if (!Directory.Exists(strDicPath))      {        Directory.CreateDirectory(strDicPath);      }      if (!File.Exists(strPath))      {        using (FileStream fs = File.Create(strPath)) { }      }      string str = File.ReadAllText(strPath);      StringBuilder sb = new StringBuilder();      foreach (var item in strList)      {        sb.Append("\r\n" + DateTime.Now.ToString() + "-----" + item + "");      }      File.WriteAllText(strPath, sb.ToString() + "\r\n-----z-----\r\n" + str);    }  }

 




原标题:c#自定义日志记录

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

eBay调整SpeedPAK中国大陆至西班牙收寄服务:https://www.ikjzd.com/articles/132124
亚马逊这些敏感词要小心了!:https://www.ikjzd.com/articles/132125
你还在发自嗨式的开发信吗?:https://www.ikjzd.com/articles/132126
亚马逊Souq中东站点开店注册条件?中东电商Souq开店运营技巧:https://www.ikjzd.com/articles/13213
欧代是什么?Amazon亚马逊卖家欧代注册流程,费用和时效详细解。:https://www.ikjzd.com/articles/132135
亚马逊推出FBA库存新功能!卖家有望申请仓储扩容!:https://www.ikjzd.com/articles/132136
亚马逊以图搜图功能再更新,99%运营不知道!:https://www.kjdsnews.com/a/1842135.html
短视频广告剪辑技巧 :https://www.kjdsnews.com/a/1842136.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流