定义日志类别的抽象
Example #1
0
        /// <summary>
        /// 获取日志消息的类型前缀,将会自动添加在每一行消息以标识这个消息的类型
        /// </summary>
        /// <param name="type">当前要记录的日志</param>
        /// <returns>当前日志消息的前缀</returns>
        protected virtual string GetTypePrefix( LogType type )
        {
            if ( type == null || type.Serverity == 0 )
            return "??";

              else if ( type.Serverity <= 500 )
            return " #";

              else if ( type == LogType.Info || type.Serverity <= 1000 )
            return "##";

              else if ( type == LogType.Warning || type.Serverity <= 2000 )
            return "#!";

              else if ( type == LogType.Error || type.Serverity <= 3000 )
            return "@!";

              else if ( type == LogType.Exception || type.Serverity <= 4000 )
            return "E!";

              else if ( type == LogType.FatalError || type.Serverity <= 5000 )
            return "F!";

              else if ( type == LogType.CrashError || type.Serverity <= 10000 )
            return "!!";

              else
            return "?!";
        }
Example #2
0
        private static void LogWithCustomType( Logger logger, LogType type, string message, params object[] args )
        {
            var meta = LogMeta.Blank;
              meta.Type = type;

              if ( args.Any() )
            message = string.Format( message, args );

              logger.LogEntry( new LogEntry( message, meta ) );
        }
Example #3
0
 public LogTypeBasedFilter( LogType type )
 {
     LogType = type;
 }
Example #4
0
        private static void LogWithCustomType( Logger logger, LogType type, string message, params object[] args )
        {
            Contract.Assert( logger != null );

              var meta = GetLogMeta( logger, type );

              if ( args.Any() )
            message = string.Format( message, args );

              logger.LogEntry( new LogEntry( message, meta ) );
        }
Example #5
0
        private static LogMeta GetLogMeta( Logger logger, LogType type )
        {
            Contract.Assert( logger != null );

              var meta = LogMeta.GetDefaultMeta().SetMetaData( type );

              var provider = logger as ILogMetaProvider;
              if ( provider != null )
            meta = provider.GetLogMeta( meta );

              return meta;
        }
Example #6
0
        /// <summary>
        /// 获取日志消息的类型前缀,将会自动添加在每一行消息以标识这个消息的类型
        /// </summary>
        /// <param name="type">当前要记录的日志</param>
        /// <returns>当前日志消息的前缀</returns>
        protected virtual string GetTypePrefix( LogType type )
        {
            if ( type == null || type.Serverity == 0 )
            return "??";

              else if ( type.Serverity <= 500 )
            return " #";

              else if ( type.Serverity <= LogType.Info.Serverity )
            return "##";

              else if ( type.Serverity <= LogType.ImportantInfo.Serverity )
            return "#@";

              else if ( type.Serverity <= LogType.Warning.Serverity )
            return "#!";

              else if ( type.Serverity <= LogType.Error.Serverity )
            return "@!";

              else if ( type.Serverity <= LogType.Exception.Serverity )
            return "E!";

              else if ( type.Serverity <= LogType.FatalError.Serverity )
            return "F!";

              else if ( type.Serverity <= LogType.CrashError.Serverity )
            return "!!";

              else
            return "?!";
        }