Here are some examples you can have a look to modify your code:
- Log4NetAdapterTests.cs - CollectingILog class: Change all method signatures to add
? for nullable parameters:
// BEFORE:
public void Debug(object message)
public void Debug(object message, Exception exception)
public void DebugFormat(string format, params object[] args)
public void DebugFormat(string format, object arg0)
public void DebugFormat(string format, object arg0, object arg1)
public void DebugFormat(string format, object arg0, object arg1, object arg2)
public void DebugFormat(IFormatProvider provider, string format, params object[] args)
// AFTER:
public void Debug(object? message)
public void Debug(object? message, Exception? exception)
public void DebugFormat(string format, params object? []? args)
public void DebugFormat(string format, object? arg0)
public void DebugFormat(string format, object? arg0, object? arg1)
public void DebugFormat(string format, object? arg0, object? arg1, object? arg2)
public void DebugFormat(IFormatProvider? provider, string format, params object?[]? args)
Apply the same pattern to all Info, Warn, Error, and Fatal methods.
- MsLoggerAdapterTests.cs - CollectingLogger class
// BEFORE:
public IDisposable BeginScope<TState>(TState state) => NullScope.Instance;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
// AFTER:
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => NullScope.Instance;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
Also fix your assertions:
// BEFORE:
Assert.True(msLogger.Messages.Any(m => m.IndexOf("hello", StringComparison.OrdinalIgnoreCase) >= 0));
// AFTER:
Assert.Contains(msLogger.Messages, m => m.Contains("hello", StringComparison.OrdinalIgnoreCase));
- MsLoggerAdapterSwallowTests.cs - ThrowingLogger class
// BEFORE:
public IDisposable BeginScope<TState>(TState state) => null;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
// AFTER:
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
Overall, just add the ? nullable annotations and generic constraints where the interfaces require them.