Пример #1
0
 /// <summary>
 /// 开始记录日志
 /// </summary>
 static void StartLogin(LogerManager loger)
 {
     try
     {
         if (loger != null)
         {
             string filePath, fileName;
             if (!IsServer)
             {
                 filePath = LogPath + "\\" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
                 fileName = filePath + "\\" + DateTime.Now.Day.ToString() + ".Log";
             }
             else
             {
                 filePath = LogPath;
                 fileName = Path.Combine(filePath, DateTime.Now.Day.TryToString() + ".Log");
             }
             if (!System.IO.Directory.Exists(filePath))
             {
                 System.IO.Directory.CreateDirectory(filePath);
             }
             FileStream   filestream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
             StreamWriter writer     = new StreamWriter(filestream, System.Text.Encoding.Default);
             writer.BaseStream.Seek(0, SeekOrigin.End);
             writer.WriteLine("{0} >{1}> {2} > {3}", DateTime.Now.TimeOfDay, loger.type.TryToString(), loger.title, loger.msg);
             writer.Flush();
             writer.Close();
             filestream.Close();
         }
     }
     catch
     {
     }
 }
Пример #2
0
        static bool logger(LogerType type, string title, string msg)
        {
            LogerManager loger = new LogerManager();

            loger.type  = type;
            loger.title = title;
            loger.msg   = msg;
            StartLogin(loger);
            return(true);
        }