Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/src/webdriver/Internal/Logging/LogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public LogContext(LogEventLevel level, ILogContext? parentLogContext, Concurrent
{
throw new ArgumentOutOfRangeException(nameof(truncationLength), "Truncation length must be non-negative.");
}

_level = level;
_parentLogContext = parentLogContext;
_loggers = CloneLoggers(loggers, level);
Expand Down
34 changes: 26 additions & 8 deletions dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,63 @@
// under the License.
// </copyright>

using System.Collections;

namespace OpenQA.Selenium.Internal.Logging;

/// <summary>
/// Represents a list of log handlers.
/// </summary>
/// <inheritdoc cref="ILogHandlerList"/>
internal sealed class LogHandlerList : List<ILogHandler>, ILogHandlerList
internal sealed class LogHandlerList : ILogHandlerList
{
private readonly ILogContext _logContext;
private readonly object _lock = new();
private volatile ILogHandler[] _handlers;

public LogHandlerList(ILogContext logContext)
{
_logContext = logContext;
_handlers = [];
}

public LogHandlerList(ILogContext logContext, IEnumerable<ILogHandler> handlers)
: base(handlers)
{
_logContext = logContext;
_handlers = [.. handlers];
}

public new ILogContext Add(ILogHandler handler)
public ILogContext Add(ILogHandler handler)
{
base.Add(handler);
lock (_lock)
{
_handlers = [.. _handlers, handler];
}

Comment thread
nvborisenko marked this conversation as resolved.
return _logContext;
}

public new ILogContext Remove(ILogHandler handler)
public ILogContext Remove(ILogHandler handler)
{
base.Remove(handler);
lock (_lock)
{
_handlers = [.. _handlers.Where(h => h != handler)];
}

Comment thread
nvborisenko marked this conversation as resolved.
return _logContext;
}

public new ILogContext Clear()
public ILogContext Clear()
{
base.Clear();
lock (_lock)
{
_handlers = [];
}

Comment thread
qodo-code-review[bot] marked this conversation as resolved.
return _logContext;
}

public IEnumerator<ILogHandler> GetEnumerator() => ((IEnumerable<ILogHandler>)_handlers).GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => _handlers.GetEnumerator();
}
Loading