コード例 #1
0
        public void should_resolve_root()
        {
            _resolver.Build(_config);

            var appenders = _resolver.ResolveAppenders("test");

            Check.That(appenders.Single().Name == "A");
        }
コード例 #2
0
        private static ZeroLogJsonConfiguration ConfigureResolver(string configFileFullPath, HierarchicalResolver resolver)
        {
            var config = ReadConfiguration(configFileFullPath);

            resolver.Build(config);
            return(config);
        }
コード例 #3
0
        public void should_resolve_appender_from_assembly_qualified_name()
        {
            var appenderDef = new AppenderDefinition
            {
                Name               = "ExtApp1",
                AppenderTypeName   = "ZeroLog.Tests.ExternalAppender.TestAppender, ZeroLog.Tests.ExternalAppender",
                AppenderJsonConfig = new DefaultAppenderConfig {
                    PrefixPattern = "[%level] @ %time - %logger: "
                }
            };

            var config = new ZeroLogJsonConfiguration
            {
                LogEventBufferSize = 5,
                LogEventQueueSize  = 7,
                RootLogger         = new LoggerDefinition
                {
                    Level = Level.Info,
                    LogEventPoolExhaustionStrategy = LogEventPoolExhaustionStrategy.DropLogMessage,
                    AppenderReferences             = new[] { "ExtApp1" },
                },
                Appenders = new[] { appenderDef },
            };

            var configResolver = new HierarchicalResolver();

            configResolver.Build(config);

            var appenders = configResolver.GetAllAppenders().ToList();

            Assert.AreEqual(1, appenders.Count);
            Assert.AreEqual("ZeroLog.Tests.ExternalAppender.TestAppender", ((GuardedAppender)appenders[0]).Appender.GetType().FullName);
        }
コード例 #4
0
        public static ILogManager ConfigureAndWatch(string configFilePath)
        {
            var configFileFullPath = Path.GetFullPath(configFilePath);

            var resolver = new HierarchicalResolver();

            var config = ConfigureResolver(configFileFullPath, resolver);

            var watcher = new FileSystemWatcher
            {
                Path                = Path.GetDirectoryName(configFileFullPath),
                NotifyFilter        = NotifyFilters.LastWrite,
                EnableRaisingEvents = true
            };

            watcher.Changed += (sender, args) =>
            {
                try
                {
                    if (!string.Equals(args.FullPath, configFileFullPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return;
                    }

                    var newConfig = ReadConfiguration(configFileFullPath);
                    resolver.Build(newConfig);
                    ConfigureGlobal(newConfig);
                }
                catch (Exception e)
                {
                    LogManager.GetLogger(typeof(JsonConfigurator))
                    .FatalFormat("Updating config failed with: {0}", e.Message);
                }
            };

            var logManager = LogManager.Initialize(resolver, config.GetInitializationConfig());

            ConfigureGlobal(config);
            return(logManager);
        }