码迷,mamicode.com
首页 > Windows程序 > 详细

C# 日志文件

时间:2015-03-11 14:16:53      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

  

using System.IO;
using System.Reflection; 
 
 private void AddLogText(string strLog)
        {

            try
            {
                string strFileName = string.Format("{0}技术分享\\XXXX.txt", GetRootPath());
                using (FileStream fs = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fs.Seek(0, SeekOrigin.End);
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
                    {
                        sw.WriteLine(strLog + DateTime.Now.ToString("HH:mm:ss"));
                    }
                }
            }
            catch
            {
            }
        }
 
 

private string GetRootPath()
{
string strPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
if (strPath.StartsWith("file:"))
{
strPath = strPath.Substring(6);
}

return strPath;
}

 

C# 日志文件

标签:

原文地址:http://www.cnblogs.com/zhouminzhang/p/4329523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!