Beispiel #1
0
        protected void WriteToFailedLog(string actionName, List <string> failedList)
        {
            var logFile = $"{actionName.Replace(" ", "_")}_failed_log.txt";
            var path    = $"{Config.ResultsDirectory}\\{logFile}";
            var sb      = new StringBuilder();

            if (File.Exists(path))
            {
                File.Delete(path);
                Logger.LogMessage($"Deleted file {path}");
                Thread.Sleep(1000);
            }

            foreach (var device in failedList)
            {
                sb.AppendLine(device);
            }

            try
            {
                FileAndFolderServices.WriteToTextFile(path, sb.ToString(), Logger);

                Logger.LogMessage($"Wrote \"{actionName}\" results to file {path}");
                ResultConsole.AddConsoleLine($"There were {failedList.Count} computers that failed the process. They have been recorded in the log at {path}");
            }
            catch (Exception e)
            {
                Logger.LogError($"Unable to write to {path}.", e);
                ResultConsole.AddConsoleLine($"There were {failedList.Count} computers that failed the process. However, there was an exception attempting to write to the failed log file.");
            }
        }
Beispiel #2
0
        private void ProcessQueue()
        {
            while (true)
            {
                if (_cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                _hasNewItems.WaitOne(WaitPeriod);

                Queue <string> queueCopy;
                lock (_queue)
                {
                    queueCopy = new Queue <string>(_queue);
                    _queue.Clear();
                }

                var sb = new StringBuilder();

                foreach (var line in queueCopy)
                {
                    sb.AppendLine(line);
                }

                try
                {
                    if (!string.IsNullOrWhiteSpace(sb.ToString()))
                    {
                        _fileAndFolderServices.WriteToTextFile(_fullLogPath, sb.ToString(), this);
                    }
                }
                catch (Exception e)
                {
                    LogFallbackException(e);
                }

                queueCopy.Clear();
            }
        }