/// <summary>
/// 產生文字檔LOG
/// </summary>
/// <param name="message"></param>
public static void WriteLog(string message)
{
    string LogPath = System.Configuration.ConfigurationSettings.AppSettings["LogPath"].ToString();
    string LogName = System.Configuration.ConfigurationSettings.AppSettings["LogName"].ToString();
    string LogType = System.Configuration.ConfigurationSettings.AppSettings["LogType"].ToString();

    if (string.IsNullOrEmpty(LogPath))
    {
        LogPath = Directory.GetCurrentDirectory();
    }
    string filename = "";
    switch (LogType)
    {
        case "Year":
            filename = LogPath +
            string.Format("\\{0}{1:yyyy}.txt", LogName, DateTime.Now);
            break;
        case "Month":
            filename = LogPath +
            string.Format("\\{0}{1:yyyyMM}.txt", LogName, DateTime.Now);
            break;
        case "Day":
            filename = LogPath +
            string.Format("\\{0}{1:yyyyMMdd}.txt", LogName, DateTime.Now);
            break;
        default:
            filename = LogPath +
            string.Format("\\{0}{1:yyyyMMdd}.txt", LogName, DateTime.Now);
            break;
    }

    FileInfo finfo = new FileInfo(filename);
    if (finfo.Directory.Exists == false)
    {
        finfo.Directory.Create();
    }
    string writeString = string.Format("{0:yyyy/MM/dd HH:mm:ss} {1}",
    DateTime.Now, message) + Environment.NewLine;
    File.AppendAllText(filename, writeString, System.Text.Encoding.Unicode);

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 波利 的頭像
    波利

    沒有魚的魚缸

    波利 發表在 痞客邦 留言(0) 人氣()