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
                    { }
                }
            }

  • 相关阅读:
    vue中$refs、$slot、$nextTick相关的语法
    js中hash、hashchange事件
    js中filter的用法
    ES6新特性-函数的简写(箭头函数)
    js中把ajax获取的数据转化成树状结构(并做成多级联动效果)
    jq中get()和eq()的区别
    new Date() 日期格式处理
    微信小程序 加载图片时,先拉长,再恢复正常
    一个例子理解ES6的yield关键字
    eclipse在光标停留在同一对象的背景色提示,开启与关闭
  • 原文地址:https://www.cnblogs.com/mmnyjq/p/2102785.html
Copyright © 2011-2022 走看看