using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.IO;
namespace PTZ_CONTROL
{
public class Log
{
private string LogPath ; //= "c://log";
private string LogName;// = "/ptzLog.log";
public Log(string path,string name)
{
LogPath = path;
LogName = "/"+name;
}
public void WriteLog(string log1,string log2)
{
try
{
DirectoryInfo d = Directory.CreateDirectory(LogPath );
FileStream fs = new FileStream(LogPath + LogName, System.IO.FileMode.Append);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.WriteLine(DateTime.Now.ToString() + "\t" + log1 + "\t" + log2);
sw.Close();
fs.Close();
}
catch
{
// // Nothing to do
}
}
}
}
本文介绍了一个使用C#编写的简单日志记录系统。该系统可以将指定的信息写入到指定路径的日志文件中,并支持追加模式。通过实例化`Log`类并调用`WriteLog`方法,用户可以方便地记录带有时间戳的日志条目。
2144

被折叠的 条评论
为什么被折叠?



