Example #1
0
 /// <summary>
 /// 写入新日志,根据指定的日志对象Msg
 /// </summary>
 /// <param name="msg">日志内容对象</param>
 public void Write(Msg msg)
 {
     if (msg != null)
     {
         lock (msgs)
         {
             msgs.Enqueue(msg);
         }
     }
 }
Example #2
0
 //写入日志文本到文件的方法
 private void FileWrite(Msg msg)
 {
     try
     {
         if (writer == null)
         {
             FileOpen();
         }
         else
         {
             //判断文件到期标志,如果当前文件到期则关闭当前文件创建新的日志文件
             if (DateTime.Now >= TimeSign)
             {
                 FileClose();
                 FileOpen();
             }
             writer.Write(msg.Datetime);
             writer.Write('\t');
             writer.Write(msg.Type);
             writer.Write('\t');
             writer.WriteLine(msg.Text);
             writer.Flush();
         }
     }
     catch (Exception e)
     {
         Console.Out.Write(e);
     }
 }