C#完成將法式運轉信息寫入日記的辦法。本站提示廣大學習愛好者:(C#完成將法式運轉信息寫入日記的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成將法式運轉信息寫入日記的辦法正文
本文實例講述了C#完成將法式運轉信息寫入日記的辦法。分享給年夜家供年夜家參考。詳細以下:
1.LogManager類
class LogManager { static object locker = new object(); /// <summary> /// 主要信息寫入日記 /// </summary> /// <param name="logs">日記列表,每條日記占一行</param> public static void WriteProgramLog(params string[] logs) { lock (locker) { string LogAddress = Environment.CurrentDirectory + "\\Log"; if (!Directory.Exists(LogAddress + "\\PRG")) { Directory.CreateDirectory(LogAddress + "\\PRG"); } LogAddress = string.Concat(LogAddress, "\\PRG\\", DateTime.Now.Year, '-', DateTime.Now.Month, '-', DateTime.Now.Day, "_program.log"); StreamWriter sw = new StreamWriter(LogAddress, true); foreach (string log in logs) { sw.WriteLine(string.Format("[{0}] {1}", DateTime.Now.ToString(), log)); } sw.Close(); } } }
2.挪用辦法
LogManager.WriteProgramLog("日記1", "日記2", "日記3");
3.運轉成果
願望本文所述對年夜家的C#法式設計有所贊助。