Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 1308245

Browse files
committed
Removing MinimumLevel from ILoggerFactory #298
1 parent 7b0f2af commit 1308245

File tree

8 files changed

+15
-102
lines changed

8 files changed

+15
-102
lines changed

src/Microsoft.Extensions.Logging.Abstractions/ILoggerFactory.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ namespace Microsoft.Extensions.Logging
1111
/// </summary>
1212
public interface ILoggerFactory : IDisposable
1313
{
14-
/// <summary>
15-
/// The minimum level of log messages sent to loggers.
16-
/// </summary>
17-
LogLevel MinimumLevel { get; set; }
18-
1914
/// <summary>
2015
/// Creates a new <see cref="ILogger"/> instance.
2116
/// </summary>

src/Microsoft.Extensions.Logging.Testing/NullLoggerFactory.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
5-
64
namespace Microsoft.Extensions.Logging.Testing
75
{
86
public class NullLoggerFactory : ILoggerFactory
97
{
108
public static readonly NullLoggerFactory Instance = new NullLoggerFactory();
119

12-
public LogLevel MinimumLevel { get; set; } = LogLevel.Verbose;
13-
1410
public ILogger CreateLogger(string name)
1511
{
1612
return NullLogger.Instance;

src/Microsoft.Extensions.Logging.Testing/TestLoggerFactory.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public TestLoggerFactory(TestSink sink, bool enabled)
1616
_enabled = enabled;
1717
}
1818

19-
public LogLevel MinimumLevel { get; set; } = LogLevel.Verbose;
20-
2119
public ILogger CreateLogger(string name)
2220
{
2321
return new TestLogger(name, _sink, _enabled);

src/Microsoft.Extensions.Logging/Logger.cs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,28 @@ public void Log(LogLevel logLevel, int eventId, object state, Exception exceptio
3737
return;
3838
}
3939

40-
if (logLevel >= _loggerFactory.MinimumLevel)
40+
List<Exception> exceptions = null;
41+
foreach (var logger in _loggers)
4142
{
42-
List<Exception> exceptions = null;
43-
foreach (var logger in _loggers)
43+
try
44+
{
45+
logger.Log(logLevel, eventId, state, exception, formatter);
46+
}
47+
catch (Exception ex)
4448
{
45-
try
49+
if (exceptions == null)
4650
{
47-
logger.Log(logLevel, eventId, state, exception, formatter);
51+
exceptions = new List<Exception>();
4852
}
49-
catch (Exception ex)
50-
{
51-
if (exceptions == null)
52-
{
53-
exceptions = new List<Exception>();
54-
}
5553

56-
exceptions.Add(ex);
57-
}
54+
exceptions.Add(ex);
5855
}
56+
}
5957

60-
if (exceptions != null && exceptions.Count > 0)
61-
{
62-
throw new AggregateException(
63-
message: "An error occurred while writing to logger(s).", innerExceptions: exceptions);
64-
}
58+
if (exceptions != null && exceptions.Count > 0)
59+
{
60+
throw new AggregateException(
61+
message: "An error occurred while writing to logger(s).", innerExceptions: exceptions);
6562
}
6663
}
6764

@@ -72,11 +69,6 @@ public bool IsEnabled(LogLevel logLevel)
7269
return false;
7370
}
7471

75-
if (logLevel < _loggerFactory.MinimumLevel)
76-
{
77-
return false;
78-
}
79-
8072
List<Exception> exceptions = null;
8173
foreach (var logger in _loggers)
8274
{

src/Microsoft.Extensions.Logging/LoggerFactory.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public ILogger CreateLogger(string categoryName)
3131
return logger;
3232
}
3333

34-
public LogLevel MinimumLevel { get; set; } = LogLevel.Verbose;
35-
3634
public void AddProvider(ILoggerProvider provider)
3735
{
3836
lock (_sync)

test/Microsoft.Extensions.Logging.Test/ConsoleLoggerTest.cs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -54,60 +54,6 @@ private Tuple<ILoggerFactory, ConsoleSink> SetUpFactory(Func<string, LogLevel, b
5454
return new Tuple<ILoggerFactory, ConsoleSink>(factory, sink);
5555
}
5656

57-
[Fact]
58-
public void MessagesAreNotLoggedWhenBelowMinimumLevel()
59-
{
60-
// arrange
61-
var t = SetUpFactory(null);
62-
var factory = t.Item1;
63-
var sink = t.Item2;
64-
var logger = factory.CreateLogger(_loggerName);
65-
66-
67-
// act
68-
logger.Log(LogLevel.Debug, 0, _state, null, null);
69-
logger.Log(LogLevel.Verbose, 0, _state, null, null);
70-
71-
// assert
72-
Assert.Equal(LogLevel.Verbose, factory.MinimumLevel);
73-
Assert.Equal(3, sink.Writes.Count);
74-
}
75-
76-
[Theory]
77-
[InlineData(LogLevel.Debug, 18, true, true)]
78-
[InlineData(LogLevel.Verbose, 15, false, true)]
79-
[InlineData(LogLevel.Information, 12, false, true)]
80-
[InlineData(LogLevel.Warning, 9, false, false)]
81-
[InlineData(LogLevel.Error, 6, false, false)]
82-
[InlineData(LogLevel.Critical, 3, false, false)]
83-
public void MinimumLogLevelCanBeChanged(
84-
LogLevel minimumLevel,
85-
int expectedMessageCount,
86-
bool enabledDebug,
87-
bool enabledInformation)
88-
{
89-
var t = SetUpFactory(null);
90-
var factory = t.Item1;
91-
var sink = t.Item2;
92-
var logger = factory.CreateLogger(_loggerName);
93-
94-
factory.MinimumLevel = minimumLevel;
95-
96-
// act
97-
logger.Log(LogLevel.Debug, 0, _state, null, null);
98-
logger.Log(LogLevel.Verbose, 0, _state, null, null);
99-
logger.Log(LogLevel.Information, 0, _state, null, null);
100-
logger.Log(LogLevel.Warning, 0, _state, null, null);
101-
logger.Log(LogLevel.Error, 0, _state, null, null);
102-
logger.Log(LogLevel.Critical, 0, _state, null, null);
103-
104-
// assert
105-
Assert.Equal(minimumLevel, factory.MinimumLevel);
106-
Assert.Equal(expectedMessageCount, sink.Writes.Count);
107-
Assert.Equal(enabledDebug, logger.IsEnabled(LogLevel.Debug));
108-
Assert.Equal(enabledInformation, logger.IsEnabled(LogLevel.Information));
109-
}
110-
11157
[Fact]
11258
public void ThrowsException_WhenNoMessageAndExceptionAreProvided()
11359
{

test/Microsoft.Extensions.Logging.Test/TestLoggerFactory.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
5-
64
namespace Microsoft.Extensions.Logging.Test
75
{
86
public class TestLoggerFactory : ILoggerFactory
@@ -16,8 +14,6 @@ public TestLoggerFactory(TestSink sink, bool enabled)
1614
_enabled = enabled;
1715
}
1816

19-
public LogLevel MinimumLevel { get; set; } = LogLevel.Verbose;
20-
2117
public ILogger CreateLogger(string categoryName)
2218
{
2319
return new TestLogger(categoryName, _sink, _enabled);

test/Microsoft.Extensions.Logging.Testing.Tests/NullLoggerFactoryTest.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
54
using Xunit;
65

76
namespace Microsoft.Extensions.Logging.Testing
87
{
98
public class NullLoggerFactoryTest
109
{
11-
[Fact]
12-
public void MinimumLevelIsVerbose()
13-
{
14-
// Act & Assert
15-
Assert.True(LogLevel.Verbose == NullLoggerFactory.Instance.MinimumLevel);
16-
}
17-
1810
[Fact]
1911
public void Create_GivesSameLogger()
2012
{

0 commit comments

Comments
 (0)