c#写log代码实现

来源:互联网 发布:电气二次接线软件 编辑:程序博客网 时间:2024/06/06 01:08
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            }        }    }}


 

原创粉丝点击