簡單的寫文本日誌方法

 

public void WriteGameLog(string msg,string logType)
{
    //建立log文件夾
    string log_path = @"C://log";
    if (!Directory.Exists(log_path))
        Directory.CreateDirectory(log_path);

    //建立log下分類文件夾
    string gameLog_path = log_path + @"//" + logType;
    if (!Directory.Exists(gameLog_path))
        Directory.CreateDirectory(gameLog_path);
    //按時間建立時間點文件
    string path = gameLog_path + @"//" + DateTime.Now.ToString("yyyy_MM_dd") + ".txt";
    File.AppendAllText(path, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + msg + Environment.NewLine);
}
相關文章
相關標籤/搜索