Ejemplo n.º 1
0
        public void AddSource(Source source, Level level, TextWriter destination)
        {
            if (source.Owner != this)
            {
                throw new LoggingException($"Attempting to add unregistered source {source}.");
            }
            if (source.Index >= _logLevels.Count)
            {
                throw new LoggingException($"Source {source} not recognized.");
            }

            if (level <= Level.NEVER)
            {
                return;
            }

            if (source.Index < 0)
            {
                // wildcard "all" source
                foreach (SourceRoutes routes in _logLevels)
                {
                    routes.AddOutput(destination, level);
                }
            }
            else
            {
                SourceRoutes routes = _logLevels[source.Index];
                routes.AddOutput(destination, level);
            }
        }
Ejemplo n.º 2
0
        public LogWriter?Log(
            Source source, Level level,
            [System.Runtime.CompilerServices.CallerMemberName] string context = "")
        {
            if (source.Owner != this || source.Index >= _logLevels.Count)
            {
                throw new LoggingException($"Source {source} not recognized.");
            }
            if (source.Index < 0)
            {
                throw new LoggingException($"Wildcard source {source} cannot be used to write to log.");
            }

            SourceRoutes routes = _logLevels[source.Index];

            if (routes.MaxVerbosity >= level)
            {
                return(new LogWriter(source, level, context, routes));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
 internal LogWriter(Source source, Level level, string context, SourceRoutes routes)
 {
     _prelude = $"{DateTime.Now,24} {source.Name,15} {level.ToString(),10} {context,30}  ";
     _level   = level;
     _routes  = routes;
 }
Ejemplo n.º 4
0
 internal LogWriter(Source source, Level level, string context, SourceRoutes routes)
 {
     _prelude = $"{DateTime.Now,24} {source.Name,15} {level.ToString(),10} {context,30}  ";
     _level = level;
     _routes = routes;
 }