Skip to content

Commit 00b579d

Browse files
committed
[dotnet] Consider log handlers as null when not initiated
1 parent dc4c7e4 commit 00b579d

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

dotnet/src/webdriver/Internal/Logging/LogContext.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ internal class LogContext : ILogContext
3535

3636
private readonly ILogContext _parentLogContext;
3737

38-
public LogContext(LogEventLevel level, ILogContext parentLogContext, ConcurrentDictionary<Type, ILogger> loggers, ILogHandlerList handlers)
38+
public LogContext(LogEventLevel level, ILogContext parentLogContext, ConcurrentDictionary<Type, ILogger> loggers, IEnumerable<ILogHandler> handlers)
3939
{
4040
_level = level;
4141

4242
_parentLogContext = parentLogContext;
4343

4444
_loggers = loggers;
4545

46-
Handlers = handlers ?? new LogHandlerList(this);
46+
if (handlers is not null)
47+
{
48+
Handlers = new LogHandlerList(this, handlers);
49+
}
4750
}
4851

4952
public ILogContext CreateContext()
@@ -60,15 +63,7 @@ public ILogContext CreateContext(LogEventLevel minimumLevel)
6063
loggers = new ConcurrentDictionary<Type, ILogger>(_loggers.Select(l => new KeyValuePair<Type, ILogger>(l.Key, new Logger(l.Value.Issuer, minimumLevel))));
6164
}
6265

63-
var context = new LogContext(minimumLevel, this, loggers, null);
64-
65-
if (Handlers != null)
66-
{
67-
foreach (var handler in Handlers)
68-
{
69-
context.Handlers.Add(handler);
70-
}
71-
}
66+
var context = new LogContext(minimumLevel, this, loggers, Handlers);
7267

7368
Log.CurrentContext = context;
7469

dotnet/src/webdriver/Internal/Logging/LogContextManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ internal class LogContextManager
2828

2929
public LogContextManager()
3030
{
31-
_globalLogContext = new LogContext(LogEventLevel.Info, null, null, null);
31+
var defaulConsoleLogHandler = new ConsoleLogHandler();
3232

33-
_globalLogContext.Handlers.Add(new ConsoleLogHandler());
33+
_globalLogContext = new LogContext(LogEventLevel.Info, null, null, new[] { defaulConsoleLogHandler });
3434
}
3535

3636
public ILogContext GlobalContext

dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// limitations under the License.
1717
// </copyright>
1818

19+
using System;
1920
using System.Collections.Generic;
2021

2122
namespace OpenQA.Selenium.Internal.Logging
@@ -33,6 +34,12 @@ public LogHandlerList(ILogContext logContext)
3334
_logContext = logContext;
3435
}
3536

37+
public LogHandlerList(ILogContext logContext, IEnumerable<ILogHandler> handlers)
38+
: base(handlers)
39+
{
40+
_logContext = logContext;
41+
}
42+
3643
public new ILogContext Add(ILogHandler handler)
3744
{
3845
base.Add(handler);

0 commit comments

Comments
 (0)