zoukankan      html  css  js  c++  java
  • 写日志

     /// <summary>
            /// 写日志文件
            /// </summary>
            /// <param name="sMsg"></param>
            public  void WriteLog(string sMsg, string fileType)
            {
                if (sMsg != "")
                {
                    string directoryPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\log";
                    //string directoryPath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath+"\\log";// System.Web.HttpContext.Current.Request.PhysicalApplicationPath;
                    //+"\\log";//路径
                    string filename = DateTime.Now.ToString("yyyyMMdd") + fileType + ".log";//文件名
                  
                    try
                    {
                        if (!Directory.Exists(directoryPath))//验证是否有路径
                        {
                            Directory.CreateDirectory(directoryPath);
                        }

                        FileInfo fi = new FileInfo(directoryPath + "\\" + filename);
                        if (!fi.Exists)
                        {
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.WriteLine(DateTime.Now + "\n" + sMsg + "\n");
                                sw.Close();
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = fi.AppendText())
                            {
                                sw.WriteLine(DateTime.Now + "\n" + sMsg + "\n");
                                sw.Close();
                            }
                        }
                    }
                    catch
                    { }
                }
            }

  • 相关阅读:
    python dict
    用Python requests beautifulSoup 获取并显示中文信息
    Python information to learn
    Python 中的异常
    Python 中的函数
    安装Linux系统Fedora 23
    (转)开源协议的比较
    WizNote for linux installation
    linux下编译bib、tex生成pdf文件
    NLP学术组织、会与论文
  • 原文地址:https://www.cnblogs.com/mmnyjq/p/2102785.html
Copyright © 2011-2022 走看看