• c#写日志方法


    //日志内容,文件名
    private string writelog(string value,string name )
            {
                string strPath = "";
                try
                {
                    strPath = System.Web.HttpContext.Current.Server.MapPath("log");
                }
                catch { }
                if (strPath == "") strPath = Application.StartupPath;
                FileStream logFile = null;
                string strDate = DateTime.Now.Year.ToString();
                strDate += "-"+DateTime.Now.Month.ToString();
                strDate += "-" + DateTime.Now.Day.ToString();
                if (!Directory.Exists(strPath+"\log"))
                    Directory.CreateDirectory(strPath+"\log");
                if (!Directory.Exists(strPath + "\log\" + strDate))
                    Directory.CreateDirectory(strPath + "\log\" + strDate);
                strPath = strPath + "\log\" + strDate + "\" + name + ".txt";
                if (logFile == null)
                    logFile = new FileStream(strPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);     
                string strLine=Environment.NewLine;
                string strTime=DateTime.Now.ToString("HH:mm:ss");
                string str = "";
                if (name != "upbeifensql" && name != "upedsql" && name != "lianjisql")
                    str = strTime + strLine;
                str += value + strLine;
                if (name != "upbeifensql" && name != "upedsql" && name != "lianjisql")
                    str += "*****************************************************************************************************************************" + strLine;
                if (name == "upbeifensql" || name == "upedsql" || name == "lianjisql")
                {
                    CompressionHelper compress = new CompressionHelper();
                    str = compress.CompressToString(str);
                    str += strLine;
                }
                byte[] bytes = System.Text.Encoding.Default.GetBytes(str);
                logFile.Position = logFile.Length;
                logFile.Write(bytes, 0, (int)bytes.Length);
                logFile.Close();
                logFile = null;
                return strPath;
            }
  • 相关阅读:
    递归实现随机数不重复问题
    今天写的一个工厂工具类
    Win7 x64 IIS运行ASP+Access故障完美解决方法(转)
    li中,标题和日期一排,且日期靠右
    [学习笔记] extends implements 的区别与联系 [转载]
    [学习笔记] vim使用大全 [转]
    MidPoint Displacement for Terrain Rendering
    CryEngine3 打造另一个真实世界
    Hello C++ AMP!
    DetailMap For Terrain Rendering
  • 原文地址:https://www.cnblogs.com/valiant1882331/p/4113004.html
Copyright © 2020-2023  润新知