Exemplo n.º 1
0
        public async Task LoggerSettings()
        {
            BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet("LoggerSettingsTest");

            settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-LogLevel", AmbientLogLevel.Error.ToString());
            settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-TypeFilter", "AllowedLoggerType");
            settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-CategoryFilter", "AllowedCategory");
            using (ScopedLocalServiceOverride <IAmbientSettingsSet> o = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settingsSet))
            {
                AmbientLogger <AllowedLoggerType> logger = new AmbientLogger <AllowedLoggerType>();
                logger.Log(new ApplicationException());

                AmbientLogger <TestLogger> testlogger = new AmbientLogger <TestLogger>();
                testlogger.Log(new ApplicationException());
                testlogger.Log(new ApplicationException(), "category", AmbientLogLevel.Information);
                testlogger.Log("test message");
                testlogger.Log(() => "test message");
                testlogger.Log("test message", "category", AmbientLogLevel.Information);
                testlogger.Log("test message", "AllowedCategory", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException());
                testlogger.Log(() => "Exception during test", new ApplicationException());
                testlogger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);

                if (_Logger.Local != null)
                {
                    await _Logger.Local.Flush();
                }
            }
        }
Exemplo n.º 2
0
        public async Task LoggerExplicitSettings()
        {
            BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet("LoggerSettingsTest");

            settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-LogLevel", AmbientLogLevel.Error.ToString());
            settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-TypeBlock", ".*[Bb]lock.*");
            settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-CategoryBlock", ".*[Bb]lock.*");
            AmbientLogger <AllowedLoggerType> logger = new AmbientLogger <AllowedLoggerType>(_Logger.Global, settingsSet);

            logger.Log(new ApplicationException());
            logger.Log(new ApplicationException(), "category", AmbientLogLevel.Information);
            logger.Log("test message");
            logger.Log(() => "test message");
            logger.Log("test message", "category", AmbientLogLevel.Information);
            logger.Log("test message", "AllowedCategory", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException());
            logger.Log(() => "Exception during test", new ApplicationException());
            logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);
            if (_Logger.Global != null)
            {
                await _Logger.Global.Flush();
            }
        }
Exemplo n.º 3
0
        public void AmbientServicesBasic()
        {
            ITest test = _Test.Global;

            Assert.IsNotNull(test);
            Assert.AreEqual(_Test.GlobalReference.Service, _Test.Global);
            IAmbientLogger logger = _Logger.Global;

            Assert.IsNotNull(logger);
            AmbientLogger <TestAmbientService> serviceBrokerLogger = new AmbientLogger <TestAmbientService>(logger);
            IAmbientProgressService            progressTracker     = _ProgressService.Global;

            Assert.IsNotNull(progressTracker);
            IAmbientSettingsSet settings = _SettingsSet.Global;

            Assert.IsNotNull(settings);
            IJunk junk = _Junk.Global;

            Assert.IsNull(junk);


            ITest compareTest = test;

            Assert.IsNotNull(test);

            int   changed     = 0;
            ITest updatedTest = test;

            Assert.IsNotNull(updatedTest);
            EventHandler <EventArgs> globalChanged = (o, e) => { updatedTest = _Test.Global; ++changed; };

            _Test.GlobalChanged += globalChanged;

            _Test.Global = null;
            Assert.AreEqual(1, changed);
            Assert.IsNull(updatedTest);
            compareTest = null;

            ITest disabledTest = _Test.Global;

            Assert.IsNull(disabledTest);

            _Test.Global = test;
            Assert.AreEqual(2, changed);
            compareTest = test;

            ITest reenabledTest = _Test.Global;

            Assert.IsNotNull(reenabledTest);

            _Test.GlobalChanged -= globalChanged;
        }
Exemplo n.º 4
0
        public void LoggerArgumentExceptions()
        {
            AmbientLogger <TestLogger> logger = new AmbientLogger <TestLogger>(_Logger.Global);
            Func <string> nullLambda          = null;
            Exception     nullException       = null;

            Assert.ThrowsException <ArgumentNullException>(() => new AmbientLogger(null !));
            Assert.ThrowsException <ArgumentNullException>(() => logger.Log(nullLambda !, "category", AmbientLogLevel.Information));
            Assert.ThrowsException <ArgumentNullException>(() => logger.Log(nullException !, "category", AmbientLogLevel.Information));
            Assert.ThrowsException <ArgumentNullException>(() => logger.Log("message", nullException !, "category", AmbientLogLevel.Information));
            Assert.ThrowsException <ArgumentNullException>(() => logger.Log(() => "message", nullException !, "category", AmbientLogLevel.Information));
            Assert.ThrowsException <ArgumentNullException>(() => logger.Log(nullLambda !, new ApplicationException(), "category", AmbientLogLevel.Information));
        }
Exemplo n.º 5
0
 public void LoggerNone()
 {
     using (new ScopedLocalServiceOverride <IAmbientLogger>(null))
     {
         AmbientLogger <TestLogger> logger = new AmbientLogger <TestLogger>();
         logger.Log(new ApplicationException());
         logger.Log(new ApplicationException(), "category", AmbientLogLevel.Information);
         logger.Log("test message");
         logger.Log(() => "test message");
         logger.Log("test message", "category", AmbientLogLevel.Information);
         logger.Log("Exception during test", new ApplicationException());
         logger.Log(() => "Exception during test", new ApplicationException());
         logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
     }
 }
Exemplo n.º 6
0
        public async Task LoggerDefault()
        {
            AmbientLogger logger = new AmbientLogger(typeof(TestLogger));

            logger.Log(new ApplicationException());
            logger.Log(new ApplicationException(), "category", AmbientLogLevel.Information);
            logger.Log("test message");
            logger.Log(() => "test message");
            logger.Log("test message", "category", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException());
            logger.Log(() => "Exception during test", new ApplicationException());
            logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
            if (_Logger.Global != null)
            {
                await _Logger.Global.Flush();
            }
        }