Ejemplo n.º 1
0
        public void Create_CreatesCorrectLogger()
        {
            var           appsettings    = @"
{
  'Logging': {
    'IncludeScopes': false,
    'LogLevel': {
        'Default': 'Information',
        'System': 'Information',
        'Microsoft': 'Information',
        'A': 'Information'
        }
    }
}";
            var           config         = GetConfig(appsettings);
            LoggerFactory fac            = new LoggerFactory();
            var           loggingSection = config.GetSection("Logging");

            var settings = new CloudFoundryLoggerSettings(loggingSection);
            var provider = new CloudFoundryLoggerProvider(settings);

            fac.AddProvider(provider);

            ILogger logger = fac.CreateLogger(typeof(A.B.C.D.TestClass));

            Assert.NotNull(logger);
            Assert.True(logger.IsEnabled(LogLevel.Information));
            Assert.False(logger.IsEnabled(LogLevel.Debug));

            provider.Dispose();
        }
Ejemplo n.º 2
0
        public void GetLoggerConfigurations_ReturnsExpected()
        {
            var           appsettings    = @"
{
  'Logging': {
    'IncludeScopes': false,
    'LogLevel': {
        'Default': 'Information',
        'System': 'Information',
        'Microsoft': 'Information',
        'A': 'Information'
        }
    }
}";
            var           config         = GetConfig(appsettings);
            LoggerFactory fac            = new LoggerFactory();
            var           loggingSection = config.GetSection("Logging");

            var settings = new CloudFoundryLoggerSettings(loggingSection);
            var provider = new CloudFoundryLoggerProvider(settings);

            fac.AddProvider(provider);

            ILogger logger = fac.CreateLogger(typeof(A.B.C.D.TestClass));

            var logConfig = provider.GetLoggerConfigurations();

            Assert.Equal(6, logConfig.Count);
            Assert.Contains(new LoggerConfiguration("Default", LogLevel.Information, LogLevel.Information), logConfig);
            Assert.Contains(new LoggerConfiguration("A.B.C.D.TestClass", null, LogLevel.Information), logConfig);
            Assert.Contains(new LoggerConfiguration("A.B.C.D", null, LogLevel.Information), logConfig);
            Assert.Contains(new LoggerConfiguration("A.B.C", null, LogLevel.Information), logConfig);
            Assert.Contains(new LoggerConfiguration("A.B", null, LogLevel.Information), logConfig);
            Assert.Contains(new LoggerConfiguration("A", LogLevel.Information, LogLevel.Information), logConfig);

            provider.Dispose();
        }