zoukankan      html  css  js  c++  java
  • c# 写入log 自己最常用的调试代码,可以适当 lock 【备用】非 log4

            public static string WriteLogFileName(string strLog, string strFileName = "MyLog")
            {
                string strPath = System.Windows.Forms.Application.StartupPath + @"Log";
                string strLogPathName = strPath + string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now).Substring(0, 9) + strFileName + ".log";
                //lock (lockerMemoLog)
                {
                    try
                    {
                        if (!Directory.Exists(strPath))
                        {
                            Directory.CreateDirectory(strPath);
                        }
                        string strLogMessage = string.Empty;
                        StreamWriter swLog;
                        {
                            strLogMessage = string.Format("{0}:#{1}", DateTime.Now, (strLog));
                        }
                        if (!File.Exists(strLogPathName))
                        {
                            swLog = new StreamWriter(strLogPathName);
                        }
                        else
                        {
                            swLog = File.AppendText(strLogPathName);
                        }
                        swLog.WriteLine(strLogMessage);
                        swLog.Close();
                        return "0";
                    }
                    catch (Exception ex)
                    {
                        return ex.ToString();
                    }
                }
            }
  • 相关阅读:
    【HDOJ】1811 Rank of Tetris
    【HDOJ】1518 Square
    日期类 Date
    RunTime
    System 系统类
    StringBuffer
    获取联系人列表的时候contact_id出现null的值
    String类
    object类
    eclipse使用的步骤
  • 原文地址:https://www.cnblogs.com/2eggs/p/13150356.html
Copyright © 2011-2022 走看看