Exemplo n.º 1
0
        public void Size_EmptyCollection_ReturnsZeroSize()
        {
            const int expectedSize = 0;
            var collection = new LoggerCollection();

            Assert.That(collection.Size(), Is.EqualTo(expectedSize));
        }
Exemplo n.º 2
0
        public Logger(Int32 count = 255)
        {
            count = count.ToRange(16);

            _messages         = new LoggerCollection(count);
            SavedMessageCount = _messages.Capacity;
        }
        /// <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);
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogKernel"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public LogKernel(LogConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration", "Log configuration cannot be null.");
            }

            _lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
            _loggers = new LoggerCollection();

            // Configure the kernel.
            this.Configure(configuration);
        }
Exemplo n.º 6
0
    private void Start()
    {
        if (!Directory.Exists(save_path))
        {
            Directory.CreateDirectory(save_path);
        }

        if (!Directory.Exists(save_path + subjectName))
        {
            Directory.CreateDirectory(save_path + subjectName);
        }

        string typeOfCamera;

        if (cameraPos.FPS)
        {
            typeOfCamera = "FPS";
        }
        else
        {
            typeOfCamera = "TPS";
        }

        string experimentType;

        if (handControl.useController)
        {
            experimentType = "Controller";
        }
        else
        {
            experimentType = "MotionCapture";
        }

        final_path = save_path + subjectName + "/" + experimentType + "_" + typeOfCamera + "_" + SceneManager.GetActiveScene().name + ".json";
        if (File.Exists(final_path))
        {
            final_path = MakeUnique(final_path);
        }

        currentLog    = new Logger();
        cumulatedLogs = new LoggerCollection();
    }
Exemplo n.º 7
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;
        }
        /// <summary>
        /// Creates a log entry on all configured loggers, based on the given
        /// message and/or exception of the specified severity, originating from the
        /// given type.
        /// </summary>
        /// <param name="type">
        /// The type from which the log request originated.
        /// </param>
        /// <param name="severity">
        /// The severity of the log entry.
        /// </param>
        /// <param name="message">
        /// The message to be logged.
        /// </param>
        /// <param name="exception">
        /// The exception to be logged.
        /// </param>
        private static void CreateLogEntry(Type type, ErrorSeverity severity, string message,
                                           Exception exception)
        {
            // retrieve collection of loggers
            LoggerCollection loggers = LogManager.GetLoggers();

            // iterate through loggers
            foreach (ILogger logger in loggers)
            {
                try
                {
                    // create log entry
                    logger.Log(type, severity, message, exception);
                }
                catch
                {
                    // sink exception
                }
            }
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Instances the specified loggers.
        /// </summary>
        /// <param name="loggers">The loggers.</param>
        /// <returns>An instance of the log helper</returns>
        public static LogHelper Instance(LoggerCollection loggers, bool logVerbose = false)
        {
            if (instance == null)
            {
                lock (syncRoot)
                {
                    if (instance == null)
                    {
                        verbose = logVerbose;
                        loggerInstances = loggers;
                        instance = new LogHelper();

                        foreach (var logger in loggers)
                        {
                            logger.Initialise();
                        }
                    }
                }
            }

            return instance;
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
0
        public void LoggerCollection_ImplementsILogger()
        {
            var collection = new LoggerCollection();

            Assert.That(collection, Is.InstanceOf<ILogger>());
        }
Exemplo n.º 13
0
        /// <summary>
        /// Server Main Entry Point - Initialize as many things as possible here.
        /// Order is important here, any additional initialization should be place at the bottom.
        /// </summary>
        /// <param name="Directory">Start Directory.</param>
        public static void Start(string Directory)
        {
            try
            {
                // Initialize Setting
                Setting = new Setting(Directory);

                // Initialize Logger.
                Logger = new LoggerCollection();
                Logger.Start();

                if (Setting.Load())
                {
                    Setting.Save();
                }
                else
                {
                    Setting.Save();
                    Environment.Exit(0);
                    return;
                }

                // Initialize Updater
                if (Setting.CheckForUpdate)
                {
                    Updater = new Updater();
                    Updater.Update();
                }

                if (Setting.MainEntryPoint == Setting.MainEntryPointType.jianmingyong_Server)
                {
                    // Initialize Listener.
                    Listener = new Server_Client_Listener.Servers.Listener();
                    Listener.Start();

                    // Initialize RCONListener.
                    if (Setting.RCONEnable)
                    {
                        RCONListener = new RCON_Client_Listener.Servers.Listener();
                        RCONListener.Start();
                    }

                    // Initialize SCONListener.
                    if (Setting.SCONEnable)
                    {
                        SCONListener = new SCON_Client_Listener.Servers.ModuleSCON();
                        SCONListener.Start();
                        //Logger.Log("SCON have been disabled due to incompatible update. Sorry for the inconvience caused.", Server_Client_Listener.Loggers.Logger.LogTypes.Info);
                    }

                    // Initialize Nancy.
                    if (Setting.NancyEnable)
                    {
                        var dataApi = new NancyData();
                        dataApi.Add("online", GetOnlineClients);

                        NancyImpl.SetDataApi(dataApi);
                        NancyImpl.Start(Setting.NancyHost, Setting.NancyPort);
                    }
                }

                // Initialize Command.
                Command = new CommandCollection();
                Command.AddCommand();
            }
            catch (Exception ex)
            {
                ex.CatchError();
            }
        }