写入log事件
来源:互联网 发布:思科查看端口流量命令 编辑:程序博客网 时间:2024/06/06 10:43
public static void Write_Log(string strLog,string type)
{
string sFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "log";
string sFileName = type + ".log";
sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径
if (!Directory.Exists(sFilePath))//验证路径是否存在
{
Directory.CreateDirectory(sFilePath);
//不存在则创建
}
FileStream fs;
StreamWriter sw;
if (File.Exists(sFileName))
//验证文件是否存在,有则追加,无则创建
{
fs = new FileStream(sFileName, FileMode.Append, FileAccess.Write);
}
else
{
fs = new FileStream(sFileName, FileMode.Create, FileAccess.Write);
}
sw = new StreamWriter(fs);
sw.WriteLine(type + " :" + strLog + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
sw.Close();
fs.Close();
}
}
{
string sFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "log";
string sFileName = type + ".log";
sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径
if (!Directory.Exists(sFilePath))//验证路径是否存在
{
Directory.CreateDirectory(sFilePath);
//不存在则创建
}
FileStream fs;
StreamWriter sw;
if (File.Exists(sFileName))
//验证文件是否存在,有则追加,无则创建
{
fs = new FileStream(sFileName, FileMode.Append, FileAccess.Write);
}
else
{
fs = new FileStream(sFileName, FileMode.Create, FileAccess.Write);
}
sw = new StreamWriter(fs);
sw.WriteLine(type + " :" + strLog + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
sw.Close();
fs.Close();
}
}
阅读全文
0 0
- 写入log事件
- unity log写入文件
- 监听Log 并写入文件
- Android测试写入文本Log
- Android将Log写入文件
- 写入事件日志中
- magento禁止LOG,写入文件和写入数据库表。
- 使用 ./a.out > log.txt 将log写入文件
- PHP如何将log信息写入服务器中的log文件
- yii2 日志操作(log)以及写入不同的log文件
- 如何向系统写入Event Log
- 使用log4j将log写入mysql
- 错误日志System.log写入问题
- c++写入应用程序日志(Event Log )
- c++写入应用程序日志(Event Log )
- Android 开发技巧之Log写入文件
- ASP.NET log写入txt文件
- QTP之轻松写入html log
- 【百日JavaScript系列】2017.11.2_函数 function
- 信息增益的理解
- javascript
- 反射reflect
- java获取公网ip地址操作
- 写入log事件
- 状态码的类别
- HTML5权威指南笔记:34-使用多媒体
- Count the Colors(zoj 1610)
- (4.1.37.1)深入理解setContentView过程和View绘制过程
- docker日志发往fluentd
- pdb调试
- mysql 存储带转义字符的字符串
- 非root用户tomcat daemon配置