zoukankan      html  css  js  c++  java
  • c# 一个记录日志的通用方法

     public static string WriteFile(string strText, string path)
            {
                Encoding code = Encoding.GetEncoding("gb2312");
                StreamWriter sw = null;
                string filename = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                try
                {
                    string fullpath = System.IO.Path.Combine(path, filename);
                    sw = new StreamWriter(fullpath, true, code);
                    sw.Write("[" + DateTime.Now.ToString() + "]
    -----------------------------
    " + strText + "
    ");
                    sw.Flush();
                }
                catch (Exception ex)
                {
                    //HttpContext.Current.Response.Write(ex.Message);
                    //HttpContext.Current.Response.End();
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Close();
                    }
                }
                return filename;
            }
    

      

  • 相关阅读:
    Java 类和对象12
    Java类和对象11
    java 类和对象10
    Java类和对象9
    Java类和对象8
    Java 类和对象7
    包装与方法
    JAVA链表
    泛型
    多态 接口
  • 原文地址:https://www.cnblogs.com/password1/p/5477799.html
Copyright © 2011-2022 走看看