每天进步一点点

it2024-01-31  59

记录一个写日志方法

public static void WriteLog(String msg)         {             StreamWriter writer = null;             try             {                 writer = File.AppendText(Application.StartupPath + @"\Log\" + "xxx.Log"+DateTime.Now.ToString("yyyy-MM-dd"));                 writer.WriteLine("{0} {1}", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"), msg);                 writer.Flush();             }             catch (Exception ex)             {                 throw ex;             }             finally             {                 if (writer != null)                 {                     writer.Close();                 }             }

        }

最新回复(0)