C++,C#Log出力,爲了調式 TickCount

::GetTickCount()  C++運行時刻

System.Environment.TickCount; C#運行時刻

 

C++ 

CFile file;
  CString strLog;
  strLog.Empty();
  file.Open("C:\\Xf4100.log", CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate);
  file.SeekToEnd();
  file.Write(strLog, strLog.GetLength());
  file.Close();

 

 

C#

public static void LogOut(string strLogTxt1, string strLogTxt2 = "", string strLogExe = "", string strFileName = "")
  {
   string strFilePath = System.Environment.CurrentDirectory;
   System.Text.StringBuilder strLog = new System.Text.StringBuilder();
   strLog.Append(DateTime.Now.ToString(@"yyyy-MM-dd hh:mm:ss fff "));
   if (!string.IsNullOrEmpty(strLogExe))
   {
    strLog.Append(DateTime.Now.ToString(strLogExe + @" "));
   }
   strLog.Append(strLogTxt1);
   if (!string.IsNullOrEmpty(strLogTxt2))
   {
    strLog.Append(@" " + strLogTxt2);
   }

   if (string.IsNullOrEmpty(strFileName))
   {
    strFileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName + DateTime.Now.ToString("_MMdd") + @".log";
   }
   else
   {
    strFileName += @".log"; ;
   }
   strFilePath += @"\" + strFileName;
   var fileStm = new System.IO.FileStream(strFilePath, System.IO.FileMode.Append, System.IO.FileAccess.Write);
   var stmWiteer = new System.IO.StreamWriter(fileStm);
   stmWiteer.WriteLine(strLog);
   stmWiteer.Close();
  
  }

 

發佈了42 篇原創文章 · 獲贊 6 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章