自己写的写日志类
来源:互联网 发布:python sin cos 编辑:程序博客网 时间:2024/05/17 08:44
应用程序在执行中可能需要记录一些信息到文件中,可以让我们日后来看。比如程序运行过程中的异常等。
这时候,可以把这些信息写到txt文件中。做为一个日志信息。下面写了一个很简单的写日志的类。本人刚刚入门,请大家提出宝贵意见。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace cacheDemo1
{
class WriteLog
{
StreamWriter streamWrite;
/// <summary>
/// 日志类
/// </summary>
/// <param name="isAppend">true 为追加</param>
public WriteLog(bool isAppend)
{
streamWrite = new StreamWriter(Application.StartupPath + @"\log.txt", isAppend);//true为追加.false覆盖
}
public void WriteLogHead()
{
streamWrite.WriteLine("-----------------------------------------------------------");
streamWrite.WriteLine("Log Start Time:" + DateTime.Now+"\n");
streamWrite.WriteLine("-----------------------------------------------------------");
streamWrite.Flush();
}
public void WriteLogContent(string strLog)
{
streamWrite.WriteLine("["+DateTime.Now+"]"+strLog);
streamWrite.Flush();
}
public void CloseStream()
{
if (streamWrite!=null)
{
streamWrite.WriteLine("Log End Time:" + DateTime.Now);
streamWrite.WriteLine("//////////////////////////////////////////////////////");
streamWrite.Flush();
streamWrite.Close();
streamWrite.Dispose();
}
}
}
}
- 自己写的写日志类
- 自己写的简易php日志类
- 自己写的C++ trace日志类
- 自己写的C++日志类log
- 开始写自己的日志!
- 自己写的日志函数
- 自己写的一个C#日志管理类
- 一篇写关于自己的日志
- 自己写的日志文件printTx
- 自己写的日志框架--linkinLog4j--日志框架的必要性
- 一个写日志的类
- 一个写日志的类
- 自己写的Array类
- 自己写的 string 类
- 自己写的SqlHelper类
- 自己写的分页类
- 自己写的String类
- 自己写的CArray类
- 统计软件SAS入门教程:SAS程序初步
- 第九章 从推销员干起
- Struts2工作流程
- javascript 客户端能力检测
- 发挥搜索引擎和工具书的大作用
- 自己写的写日志类
- UVA 11234
- MSSQL英儿版基础整理二
- 重装系统之后 Oracle 数据库的恢复的方法
- 文件选择框类 OpenFileDialog类
- 如何设置ssh本机时不输入密码
- ScriptCase开发平台介绍(十二)——控制(Control)应用程序
- hibenate.hbm2ddl.auto属性详解
- 骑摩托被线勒住脖子 男子险遭风筝线割喉