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

  • 相关阅读:
    Flex弹性盒模型
    响应式布局rem的使用
    京东首页如何实现pc端和移动端加载不同的html的?
    canvas绘制表盘时钟
    javascript实现ul中列表项随机排列
    使用 HTML5 视频事件
    Javascript获取当前鼠标在元素内的坐标定位
    移动 web 开发问题和优化小结
    关于fisher判别的一点理解
    机器学习第三课(EM算法和高斯混合模型)
  • 原文地址:https://www.cnblogs.com/mmnyjq/p/2102785.html
Copyright © 2011-2022 走看看