zoukankan      html  css  js  c++  java
  • C# 利用file打印日志

      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
                {
                }
            }
        }
  • 相关阅读:
    [洛谷P4585] [FJOI2015] 火星商店问题
    [bzoj4311] 向量
    [bzoj4977] [Lydsy1708月赛] 跳伞求生
    sdut-1153 C语言实验——求两个整数之中较大者
    sdut_1116
    sdut_1189
    汉诺塔
    二分查找
    类似二分查找算法
    [YTU]_2922(Shape系列-8)
  • 原文地址:https://www.cnblogs.com/wangboke/p/5854144.html
Copyright © 2011-2022 走看看