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

C# 利用file打印日志

时间:2016-09-08 20:09:39      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

  public class FaceLog
    {
        public static void AppendInfoLog(string errMsg)
        {
            try
            {
                string Folder = Main.Instance.AppPath + "\\Logs\\";
                string fileName = Folder + "Info_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                if (!System.IO.Directory.Exists(Folder))
                    System.IO.Directory.CreateDirectory(Folder);
                if (!File.Exists(fileName))
                    System.IO.File.Create(fileName);
                using (TextWriter fs = new StreamWriter(fileName, true))
                {
                    fs.WriteLine("--------------------------" + DateTime.Now.ToString() + "----------------------------------------");
                    fs.WriteLine(errMsg);
                    fs.WriteLine("");
                    fs.WriteLine("");
                    fs.Close();
                    fs.Dispose();
                }
            }
            catch
            {
            }
        }
        public static void AppendErrorLog(string errMsg)
        {
            try
            {
                string Folder = Main.Instance.AppPath + "\\Logs\\";
                string fileName = Folder + "Error_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                if (!System.IO.Directory.Exists(Folder))
                    System.IO.Directory.CreateDirectory(Folder);
                if (!File.Exists(fileName))
                    System.IO.File.Create(fileName);
                using (TextWriter fs = new StreamWriter(fileName, true))
                {
                    fs.WriteLine("--------------------------" + DateTime.Now.ToString() + "----------------------------------------");
                    fs.WriteLine(errMsg);
                    fs.WriteLine("");
                    fs.WriteLine("");
                    fs.Close();
                    fs.Dispose();
                }
            }
            catch
            {
            }
        }
    }

 

C# 利用file打印日志

标签:

原文地址:http://www.cnblogs.com/wangboke/p/5854144.html

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