diff --git a/dotnet/src/webdriver/Internal/Logging/ConsoleLogHandler.cs b/dotnet/src/webdriver/Internal/Logging/ConsoleLogHandler.cs
index 32a51421bf524..30a1a36efe128 100644
--- a/dotnet/src/webdriver/Internal/Logging/ConsoleLogHandler.cs
+++ b/dotnet/src/webdriver/Internal/Logging/ConsoleLogHandler.cs
@@ -19,6 +19,8 @@
using System;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
diff --git a/dotnet/src/webdriver/Internal/Logging/FileLogHandler.cs b/dotnet/src/webdriver/Internal/Logging/FileLogHandler.cs
index 8c92cf46aa3b4..7bb673486f793 100644
--- a/dotnet/src/webdriver/Internal/Logging/FileLogHandler.cs
+++ b/dotnet/src/webdriver/Internal/Logging/FileLogHandler.cs
@@ -20,6 +20,8 @@
using System;
using System.IO;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
@@ -40,6 +42,7 @@ public class FileLogHandler : ILogHandler, IDisposable
/// Initializes a new instance of the class with the specified file path.
///
/// The path of the log file.
+ /// If is or .
public FileLogHandler(string filePath)
: this(filePath, overwrite: true)
{
@@ -51,6 +54,7 @@ public FileLogHandler(string filePath)
///
/// The path of the log file.
/// Specifies whether the file should be overwritten if it exists on the disk.
+ /// If is or .
public FileLogHandler(string filePath, bool overwrite)
{
if (string.IsNullOrEmpty(filePath)) throw new ArgumentException("File log path cannot be null or empty.", nameof(filePath));
@@ -112,9 +116,9 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
_streamWriter?.Dispose();
- _streamWriter = null;
+ _streamWriter = null!;
_fileStream?.Dispose();
- _fileStream = null;
+ _fileStream = null!;
}
_isDisposed = true;
diff --git a/dotnet/src/webdriver/Internal/Logging/ILogContext.cs b/dotnet/src/webdriver/Internal/Logging/ILogContext.cs
index d1cc52cae4509..321c2bc99bd07 100644
--- a/dotnet/src/webdriver/Internal/Logging/ILogContext.cs
+++ b/dotnet/src/webdriver/Internal/Logging/ILogContext.cs
@@ -19,6 +19,8 @@
using System;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
diff --git a/dotnet/src/webdriver/Internal/Logging/ILogHandler.cs b/dotnet/src/webdriver/Internal/Logging/ILogHandler.cs
index 59c8133d007b3..c7ab4cc7bb0c1 100644
--- a/dotnet/src/webdriver/Internal/Logging/ILogHandler.cs
+++ b/dotnet/src/webdriver/Internal/Logging/ILogHandler.cs
@@ -17,6 +17,8 @@
// under the License.
//
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
diff --git a/dotnet/src/webdriver/Internal/Logging/ILogHandlerList.cs b/dotnet/src/webdriver/Internal/Logging/ILogHandlerList.cs
index f27b10a53b416..4930613c86957 100644
--- a/dotnet/src/webdriver/Internal/Logging/ILogHandlerList.cs
+++ b/dotnet/src/webdriver/Internal/Logging/ILogHandlerList.cs
@@ -19,6 +19,8 @@
using System.Collections.Generic;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
diff --git a/dotnet/src/webdriver/Internal/Logging/ILogger.cs b/dotnet/src/webdriver/Internal/Logging/ILogger.cs
index a92a43e0d8445..ab2713722894b 100644
--- a/dotnet/src/webdriver/Internal/Logging/ILogger.cs
+++ b/dotnet/src/webdriver/Internal/Logging/ILogger.cs
@@ -19,6 +19,8 @@
using System;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
diff --git a/dotnet/src/webdriver/Internal/Logging/Log.cs b/dotnet/src/webdriver/Internal/Logging/Log.cs
index 884e147c8659a..01b40ac2bc9fd 100644
--- a/dotnet/src/webdriver/Internal/Logging/Log.cs
+++ b/dotnet/src/webdriver/Internal/Logging/Log.cs
@@ -18,6 +18,9 @@
//
using System;
+using System.Diagnostics.CodeAnalysis;
+
+#nullable enable
namespace OpenQA.Selenium.Internal.Logging
{
@@ -65,16 +68,11 @@ public static ILogContext CreateContext(LogEventLevel minimumLevel)
///
/// Gets or sets the current log context.
///
+ [AllowNull]
internal static ILogContext CurrentContext
{
- get
- {
- return _logContextManager.CurrentContext;
- }
- set
- {
- _logContextManager.CurrentContext = value;
- }
+ get => _logContextManager.CurrentContext;
+ set => _logContextManager.CurrentContext = value;
}
///
diff --git a/dotnet/src/webdriver/Internal/Logging/LogContext.cs b/dotnet/src/webdriver/Internal/Logging/LogContext.cs
index ccf902fb9b35b..bb4d9feede2c5 100644
--- a/dotnet/src/webdriver/Internal/Logging/LogContext.cs
+++ b/dotnet/src/webdriver/Internal/Logging/LogContext.cs
@@ -22,6 +22,8 @@
using System.Collections.Generic;
using System.Linq;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
@@ -30,15 +32,15 @@ namespace OpenQA.Selenium.Internal.Logging
///
internal class LogContext : ILogContext
{
- private ConcurrentDictionary _loggers;
+ private ConcurrentDictionary? _loggers;
private LogEventLevel _level;
- private readonly ILogContext _parentLogContext;
+ private readonly ILogContext? _parentLogContext;
private readonly Lazy _lazyLogHandlerList;
- public LogContext(LogEventLevel level, ILogContext parentLogContext, ConcurrentDictionary loggers, IEnumerable handlers)
+ public LogContext(LogEventLevel level, ILogContext? parentLogContext, ConcurrentDictionary? loggers, IEnumerable? handlers)
{
_level = level;
@@ -63,7 +65,7 @@ public ILogContext CreateContext()
public ILogContext CreateContext(LogEventLevel minimumLevel)
{
- ConcurrentDictionary loggers = null;
+ ConcurrentDictionary? loggers = null;
if (_loggers != null)
{
@@ -89,12 +91,9 @@ public ILogger GetLogger(Type type)
throw new ArgumentNullException(nameof(type));
}
- if (_loggers is null)
- {
- _loggers = new ConcurrentDictionary();
- }
+ _loggers ??= new ConcurrentDictionary();
- return _loggers.GetOrAdd(type, _ => new Logger(type, _level));
+ return _loggers.GetOrAdd(type, type => new Logger(type, _level));
}
public bool IsEnabled(ILogger logger, LogEventLevel level)
diff --git a/dotnet/src/webdriver/Internal/Logging/LogContextManager.cs b/dotnet/src/webdriver/Internal/Logging/LogContextManager.cs
index 41594f1125447..834e806d8b74a 100644
--- a/dotnet/src/webdriver/Internal/Logging/LogContextManager.cs
+++ b/dotnet/src/webdriver/Internal/Logging/LogContextManager.cs
@@ -17,45 +17,31 @@
// under the License.
//
+using System.Diagnostics.CodeAnalysis;
using System.Threading;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
internal class LogContextManager
{
- private readonly ILogContext _globalLogContext;
-
- private readonly AsyncLocal _currentAmbientLogContext = new AsyncLocal();
+ private readonly AsyncLocal _currentAmbientLogContext = new AsyncLocal();
public LogContextManager()
{
var defaulConsoleLogHandler = new ConsoleLogHandler();
- _globalLogContext = new LogContext(LogEventLevel.Info, null, null, new[] { defaulConsoleLogHandler });
+ GlobalContext = new LogContext(LogEventLevel.Info, null, null, new[] { defaulConsoleLogHandler });
}
- public ILogContext GlobalContext
- {
- get { return _globalLogContext; }
- }
+ public ILogContext GlobalContext { get; }
+ [AllowNull]
public ILogContext CurrentContext
{
- get
- {
- if (_currentAmbientLogContext.Value is null)
- {
- return _globalLogContext;
- }
- else
- {
- return _currentAmbientLogContext.Value;
- }
- }
- set
- {
- _currentAmbientLogContext.Value = value;
- }
+ get => _currentAmbientLogContext.Value ?? GlobalContext;
+ set => _currentAmbientLogContext.Value = value;
}
}
}
diff --git a/dotnet/src/webdriver/Internal/Logging/LogEvent.cs b/dotnet/src/webdriver/Internal/Logging/LogEvent.cs
index 2a4f9daaf27f9..2fad19a93dc2b 100644
--- a/dotnet/src/webdriver/Internal/Logging/LogEvent.cs
+++ b/dotnet/src/webdriver/Internal/Logging/LogEvent.cs
@@ -19,6 +19,8 @@
using System;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
@@ -33,9 +35,10 @@ public sealed class LogEvent
/// The timestamp of the log event.
/// The level of the log event.
/// The message of the log event.
+ /// If is .
public LogEvent(Type issuedBy, DateTimeOffset timestamp, LogEventLevel level, string message)
{
- IssuedBy = issuedBy;
+ IssuedBy = issuedBy ?? throw new ArgumentNullException(nameof(issuedBy));
Timestamp = timestamp;
Level = level;
Message = message;
diff --git a/dotnet/src/webdriver/Internal/Logging/LogEventLevel.cs b/dotnet/src/webdriver/Internal/Logging/LogEventLevel.cs
index af8b728f0d326..57090b75de4e7 100644
--- a/dotnet/src/webdriver/Internal/Logging/LogEventLevel.cs
+++ b/dotnet/src/webdriver/Internal/Logging/LogEventLevel.cs
@@ -17,6 +17,8 @@
// under the License.
//
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
diff --git a/dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs b/dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs
index 7c75c36f4b2cf..9f05d3d5c52fa 100644
--- a/dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs
+++ b/dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs
@@ -19,13 +19,15 @@
using System.Collections.Generic;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
/// Represents a list of log handlers.
///
///
- internal class LogHandlerList : List, ILogHandlerList
+ internal sealed class LogHandlerList : List, ILogHandlerList
{
private readonly ILogContext _logContext;
diff --git a/dotnet/src/webdriver/Internal/Logging/Logger.cs b/dotnet/src/webdriver/Internal/Logging/Logger.cs
index 0c92d0c0f299f..058d7944af153 100644
--- a/dotnet/src/webdriver/Internal/Logging/Logger.cs
+++ b/dotnet/src/webdriver/Internal/Logging/Logger.cs
@@ -19,13 +19,15 @@
using System;
+#nullable enable
+
namespace OpenQA.Selenium.Internal.Logging
{
///
/// The implementation of the interface through which log messages are emitted.
///
///
- internal class Logger : ILogger
+ internal sealed class Logger : ILogger
{
public Logger(Type issuer, LogEventLevel level)
{