asp.net写入日志到文本文件
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
[csharp]?view plain?copy
using?System;??
using?System.Collections.Generic;??
using?System.Web;??
using?System.IO;??
using?System.Text;??
??
///?<summary>??
///?Summary?description?for?NetLog??
///?</summary>??
public?class?NetLog??
{??
????///?<summary>??
????///?寫入日志到文本文件??
????///?</summary>??
????///?<param?name="action">動作</param>??
????///?<param?name="strMessage">日志內容</param>??
????///?<param?name="time">時間</param>??
????public?static?void?WriteTextLog(string?action,?string?strMessage,?DateTime?time)??
????{??
????????string?path?=?AppDomain.CurrentDomain.BaseDirectory?+?@"System\Log\";??
????????if?(!Directory.Exists(path))??
????????????Directory.CreateDirectory(path);??
??
????????string?fileFullPath?=?path?+?time.ToString("yyyy-MM-dd")?+?".System.txt";??
????????StringBuilder?str?=?new?StringBuilder();??
????????str.Append("Time:????"?+?time.ToString()?+?"\r\n");??
????????str.Append("Action:??"?+?action?+?"\r\n");??
????????str.Append("Message:?"?+?strMessage?+?"\r\n");??
????????str.Append("-----------------------------------------------------------\r\n\r\n");??
????????StreamWriter?sw;??
????????if?(!File.Exists(fileFullPath))??
????????{??
????????????sw?=?File.CreateText(fileFullPath);??
????????}??
????????else??
????????{??
????????????sw?=?File.AppendText(fileFullPath);??
????????}??
????????sw.WriteLine(str.ToString());??
????????sw.Close();??
????}??
}??
轉載于:https://my.oschina.net/u/1777508/blog/620991
總結
以上是生活随笔為你收集整理的asp.net写入日志到文本文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: apache 一个站点配置多个域名
- 下一篇: 1号店Interview小结