/// <summary>
        /// Retrieves the configured collection of loggers.
        /// </summary>
        /// <returns>
        /// The collection of configured loggers.
        /// </returns>
        private static LoggerCollection GetLoggers()
        {
            LoggerCollection loggers = new LoggerCollection();

            // create loggers
            loggers.Add(new Core.Diagnostics.Logging.Loggers.Log4NetLogger());

            return(loggers);
        }
Esempio n. 2
0
        public void Add_AddingLoggerToCollection_ReturnsCorrectSize()
        {
            const int expectedSize = 1;
            var collection = new LoggerCollection();
            var logger = new ConsoleLogger();

            collection.Add(logger);

            Assert.That(collection.Size(), Is.EqualTo(expectedSize));
        }
Esempio n. 3
0
        public static ILogger Create(Options options)
        {
            ILogger logger;

            if (options.LogError)
            {
                var collection = new LoggerCollection();
                collection.Add(new ConsoleLogger());
                collection.Add(new FileLogger(new FileHelper()));

                logger = collection;
            }
            else
            {
                logger = new ConsoleLogger();
            }

            return logger;
        }
Esempio n. 4
0
        public void Log_CallingLog_CallsInternalLoggersLogMethodTheCorrectNumberOfTimes()
        {
            var collection = new LoggerCollection();
            var logger1 = new Mock<ILogger>();
            var logger2 = new Mock<ILogger>();

            logger1.Setup(m => m.Log(It.IsAny<Check>()));
            logger2.Setup(m => m.Log(It.IsAny<Check>()));

            collection.Add(logger1.Object);
            collection.Add(logger2.Object);

            collection.Log(new Check
                           	{
                           		Url = "http://www.google.com/",
                                Status = 200
                           	});

            logger1.Verify(f => f.Log(It.IsAny<Check>()), Times.Once());
            logger2.Verify(f => f.Log(It.IsAny<Check>()), Times.Once());
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            PrintAbout();

            bool pauseOnExit = true;

            var consoleLogger = new FilteredLogger(new ConsoleLogger());
            var counter       = new LogCounter();

            var loggers = new LoggerCollection {
                consoleLogger, counter
            };
            FileOutputLogger fileLogger = null;

            var parser = new CommandLineParser();

            foreach (var @switch in CommandLineSwitches.AllSwitches)
            {
                parser.AddSwitch(@switch);
            }

            try
            {
                var result = parser.Parse(args);
                if (result.Flags.Contains(CommandLineSwitches.EnableTroublenoobing))
                {
                    throw new DevirtualisationException("Magikarp uses Splash! It was not very effective...");
                }

                pauseOnExit = !result.Flags.Contains(CommandLineSwitches.NoPause);

                if (result.Flags.Contains(CommandLineSwitches.Help))
                {
                    PrintHelp();
                }
                else
                {
                    consoleLogger.IncludeDebug = result.Flags.Contains(CommandLineSwitches.VerboseOutput) ||
                                                 result.Flags.Contains(CommandLineSwitches.VeryVerboseOutput);
                    consoleLogger.IncludeDebug2 = result.Flags.Contains(CommandLineSwitches.VeryVerboseOutput);

                    var options = GetDevirtualisationOptions(result);
                    options.OutputOptions.EnsureDirectoriesExist();

                    if (result.Flags.Contains(CommandLineSwitches.OutputLogFile))
                    {
                        fileLogger =
                            new FileOutputLogger(Path.Combine(options.OutputOptions.RootDirectory, "report.log"));
                        loggers.Add(fileLogger);
                    }

                    if (result.Flags.Contains(CommandLineSwitches.SalvageData))
                    {
                        loggers.Warning(Tag,
                                        "Salvage mode is enabled. Output files might not be an accurate representation of the original binary.");
                    }

                    var devirtualiser = new Devirtualiser(loggers);
                    devirtualiser.Devirtualise(options);
                }
            }
            catch (CommandLineParseException ex)
            {
                consoleLogger.Error(Tag, ex.Message);
                consoleLogger.Log(Tag, "Use -h for help.");
            }
            catch (Exception ex) when(!Debugger.IsAttached)
            {
                consoleLogger.Error(Tag, "Something went wrong! Try the latest version or report a bug at the repository.");
                if (consoleLogger.IncludeDebug)
                {
                    loggers.Error(Tag, ex.ToString());
                }
                else
                {
                    PrintExceptions(new LoggerCollection {
                        consoleLogger, counter
                    }, new[] { ex });
                    fileLogger?.Error(Tag, ex.ToString());
                    consoleLogger.Error(Tag, "Use --verbose or inspect the full report.log using --log-file for more details.");
                }
            }
            finally
            {
                loggers.Log(Tag, $"Process finished with {counter.Warnings} warnings and {counter.Errors} errors.");
                fileLogger?.Dispose();
            }

            if (pauseOnExit)
            {
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Esempio n. 6
0
 public void Log(LogMessage message)
 {
     _messages.Add(message);
     Logged?.Invoke(message);
 }