Exemple #1
0
 public Deferred(LogState state)
 {
     _state  = state;
     _writer = state._deferWriter;
     _color  = state._deferColor;
     _line   = state._deferLine;
     _time   = state._deferTime;
 }
Exemple #2
0
        public Log(TextWriter outWriter = null, TextWriter errorWriter = null, LogState state = null)
        {
            if (outWriter == null)
            {
                outWriter = Console.Out;
            }
            if (errorWriter == null)
            {
                errorWriter = outWriter == Console.Out
                                ? Console.Error
                                : outWriter;
            }

            _state          = state ?? new LogState();
            OutWriter       = new LogWriter(_state, outWriter);
            ErrorWriter     = new LogWriter(_state, errorWriter);
            EnableAnimation = outWriter == Console.Out && !Console.IsOutputRedirected;
        }
Exemple #3
0
        internal IDisposable BeginDeferred(TextWriter writer, string line, ConsoleColor?color, bool animate)
        {
            if (writer == TextWriter.Null)
            {
                return(writer);
            }

            Flush(writer);
            SetColor(writer, color);
            writer.Write(line);

            _deferLine   = line;
            _deferTime   = Time;
            _deferWriter = writer;
            _deferColor  = color;
            _lastLine    = null;

            if (animate)
            {
                if (_timer == null)
                {
                    _timer          = new Timer(_interval);
                    _timer.Elapsed += (_, __) => {
                        lock (_animated)
                            if (_timer.Enabled)               // Check race condition
                            {
                                lock (_animated._deferWriter) // Don't race with i.e. Stuff.Log
                                    _animated.Tick();
                            }                                 // (or anything locking Console.Out)
                    };
                }

                _animated      = this;
                _timer.Enabled = true;
            }

            return(new Deferred(this));
        }
Exemple #4
0
 public Log(IErrorList errors, TextWriter outWriter = null, TextWriter errorWriter = null, LogState state = null)
     : this(outWriter, errorWriter, state)
 {
     Errors = errors ?? ErrorList.Null;
 }
Exemple #5
0
 internal LogWriter(LogState state, TextWriter w)
 {
     _state = state;
     Inner  = (w as LogWriter)?.Inner ?? w;
 }