sealed class Log
    {
        private const string LogPath = @"C:\test\ex.log";
        private StreamWriter log;
        public static readonly Log instance = new Log();

        private Log()
        {
            log = new StreamWriter(LogPath, true);
        }

        public void WriteInfo(string message)
        {
            WriteInfo("{0}", message);
        }

        public void WriteInfo(string format, params object[] obj)
        {
            try
            {
                log.WriteLine( string.Format("[{0}] {1}",System.DateTime.Now,string.Format(format, obj)));
                log.Flush();
            }
            catch
            {
                // Nothing to do
            }
        }
    }

   Log分级
   web.config文件:
   logLevel=0  0:没有LOg,1:全部Log含Debug Log,2:运行log

   public void logLevel1(string message)
   {  
          if (logLevel == 0)
          {
           return;
          }else
          {
              WriteInfo(message);
          }
}

public void logLevel2(string message)
   {  
          if (logLevel == 2)
          {
           WriteInfo(message);
             }else
          {
              return;
          }
}
  
  
10-31 11:21
查看更多