Exemple #1
0
        /// <summary>
        /// Start capturing of the standard output channel.
        /// </summary>
        /// <param name="cache">If set to <c>true</c> output will be cached, and periodically written.</param>
        public static void StartCapture(bool cache = true)
        {
            // Determine if we need to move old log files out of the way
            string logPath = Path.Combine(Platform.GetBaseDirectory(), _outputFileName);

            if (File.Exists(logPath))
            {
                // Get count of log files
                int count = Directory.GetFiles(Platform.GetBaseDirectory(), _outputFileName + "*").Length;

                // Move the latest to its new number
                File.Move(logPath, logPath + "." + count.ToString().PadLeft(3, '0'));
            }

            _writer = new Services.LogWriter(logPath, Console.OutputEncoding, Console.Out)
            {
                UseCache = cache
            };
            Console.SetOut(_writer);

            // Setup safety thread
            _periodicWriter = new Timer(
                e => WriteCache(),
                null, TimeSpan.Zero,
                TimeSpan.FromMinutes(1));
        }
Exemple #2
0
        /// <summary>
        /// Stop capturing the standard output channel.
        /// </summary>
        public static void StopCapture()
        {
            // Do we have period writing
            if (_periodicWriter != null)
            {
                _periodicWriter.Dispose();
                _periodicWriter = null;
            }

            // Do we have a writer?
            if (_writer != null)
            {
                WriteCache();
                _writer.UseCache = false;
                _writer          = null;
            }
        }