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

  • 相关阅读:
    跨媒体安全
    kali视频(21-25)学习
    kali视频(26-30)学习
    kali视频(16-20)学习
    kali视频学习(11-15)
    kali视频(1-5)
    使用Metaspoit攻击MS08-067
    web应用程序安全攻防---sql注入和xss跨站脚本攻击
    -区块链-
    TCP/IP网络协议攻击
  • 原文地址:https://www.cnblogs.com/mmnyjq/p/2102785.html
Copyright © 2011-2022 走看看