ASP.net 写入日志到文本文件
2017-10-13 15:30
381 查看
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(); }
相关文章推荐
- asp.net写入日志到文本文件
- asp.net写入日志到文本文件
- asp.net写入日志到文本文件
- .NET跨平台之旅:在Linux上将ASP.NET 5运行日志写入文件
- 用ASP.NET将网页错误信息写入系统日志
- asp.net错误日志写入
- 如何用在ASP.NET中写入事件日志
- 用ASP.NET将网页错误信息写入系统日志
- asp.net读取模版并写入文本文件
- 用ASP.NET将网页错误信息写入系统日志
- asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库
- 用ASP.NET将网页错误信息写入系统日志
- asp.net利用log4net写入日志到SqlServer数据库
- asp.net错误日志写入
- asp.net错误日志写入
- 用ASP.NET将网页错误信息写入系统日志
- 如何用在asp.net中写入事件日志
- asp.net利用log4net写入日志到SqlServer数据库[整理]
- 如何用在ASP.NET中写入事件日志
- asp.net错误日志写入