Loading...

          java .net

          C# 寫日志到文件

          using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Windows.Forms;
          using System.IO;

          namespace psms.util
          {
              class Log
              {
                  /// <summary>
                  /// 寫日志文件
                  /// </summary>
                  /// <param name="sMsg"></param>
                  public static void WriteLog(string sMsg)
                  {
                      if (sMsg != "")
                      {
                          //Random randObj = new Random(DateTime.Now.Millisecond);
                          //int file = randObj.Next() + 1;
                          string filename = DateTime.Now.ToString("yyyyMM") + ".log";
                          try
                          {
                              FileInfo fi = new FileInfo(Application.StartupPath + "\\log\\" + filename);
                              if (!fi.Exists)
                              {
                                  using (StreamWriter sw = fi.CreateText())
                                  {
                                      sw.WriteLine(DateTime.Now + "\n" + sMsg + "\n");
                                      sw.Close();
                                  }
                              }
                              else
                              {
                                  using (StreamWriter sw = fi.AppendText())
                                  {
                                      sw.WriteLine(DateTime.Now + "\n" + sMsg + "\n");
                                      sw.Close();
                                  }
                              }
                          }
                          catch(Exception ex)
                          {
                              Console.WriteLine(ex.Message);
                          }
                      }
                  }
              }
          }

          posted on 2008-08-26 22:06 閱讀(1740) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          公告

          希望有一天

          我能用鼠標雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導航

          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          統計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 邯郸县| 天峨县| 周至县| 太仓市| 桐城市| 安义县| 元朗区| 云浮市| 建阳市| 马山县| 镇江市| 平江县| 杨浦区| 封丘县| 竹北市| 贺州市| 丰顺县| 东安县| 梨树县| 加查县| 玉山县| 南阳市| 东方市| 青川县| 弥勒县| 常宁市| 辽中县| 洞头县| 铜鼓县| 温州市| 交城县| 南和县| 遵化市| 东阿县| 新干县| 铜川市| 左云县| 西安市| 板桥市| 安庆市| 潞西市|