Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6945933
  • 博文数量: 701
  • 博客积分: 10821
  • 博客等级: 上将
  • 技术积分: 12021
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-02 10:41
个人简介

中科院架构师,专注企业数字化各个方面,MES/ERP/CRM/OA、物联网、传感器、大数据、ML、AI、云计算openstack、Linux、SpringCloud。

文章分类

全部博文(701)

分类: 项目管理

2011-04-07 10:50:09

    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;
          }
}
  
  
阅读(17373) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~