diff --git a/src/libraries/Common/src/Extensions/Logging/NullExternalScopeProvider.cs b/src/libraries/Common/src/Extensions/Logging/NullExternalScopeProvider.cs index 17936083a934dd..791ecc87152cd0 100644 --- a/src/libraries/Common/src/Extensions/Logging/NullExternalScopeProvider.cs +++ b/src/libraries/Common/src/Extensions/Logging/NullExternalScopeProvider.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + using System; namespace Microsoft.Extensions.Logging @@ -20,12 +22,12 @@ private NullExternalScopeProvider() public static IExternalScopeProvider Instance { get; } = new NullExternalScopeProvider(); /// - void IExternalScopeProvider.ForEachScope(Action callback, TState state) + void IExternalScopeProvider.ForEachScope(Action callback, TState state) { } /// - IDisposable IExternalScopeProvider.Push(object state) + IDisposable IExternalScopeProvider.Push(object? state) { return NullScope.Instance; } diff --git a/src/libraries/Common/src/Extensions/TypeNameHelper/TypeNameHelper.cs b/src/libraries/Common/src/Extensions/TypeNameHelper/TypeNameHelper.cs index 66d767c3fdf88b..1377491df5cfa7 100644 --- a/src/libraries/Common/src/Extensions/TypeNameHelper/TypeNameHelper.cs +++ b/src/libraries/Common/src/Extensions/TypeNameHelper/TypeNameHelper.cs @@ -1,9 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + using System; using System.Text; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.Extensions.Internal { @@ -31,7 +34,8 @@ internal static class TypeNameHelper { typeof(ushort), "ushort" } }; - public static string GetTypeDisplayName(object item, bool fullName = true) + [return: NotNullIfNotNull("item")] + public static string? GetTypeDisplayName(object? item, bool fullName = true) { return item == null ? null : GetTypeDisplayName(item.GetType(), fullName); } @@ -63,7 +67,7 @@ private static void ProcessType(StringBuilder builder, Type type, in DisplayName { ProcessArrayType(builder, type, options); } - else if (_builtInTypeNames.TryGetValue(type, out string builtInName)) + else if (_builtInTypeNames.TryGetValue(type, out string? builtInName)) { builder.Append(builtInName); } @@ -76,7 +80,7 @@ private static void ProcessType(StringBuilder builder, Type type, in DisplayName } else { - string name = options.FullName ? type.FullName : type.Name; + string name = options.FullName ? type.FullName! : type.Name; builder.Append(name); if (options.NestedTypeDelimiter != DefaultNestedTypeDelimiter) @@ -91,7 +95,7 @@ private static void ProcessArrayType(StringBuilder builder, Type type, in Displa Type innerType = type; while (innerType.IsArray) { - innerType = innerType.GetElementType(); + innerType = innerType.GetElementType()!; } ProcessType(builder, innerType, options); @@ -101,7 +105,7 @@ private static void ProcessArrayType(StringBuilder builder, Type type, in Displa builder.Append('['); builder.Append(',', type.GetArrayRank() - 1); builder.Append(']'); - type = type.GetElementType(); + type = type.GetElementType()!; } } @@ -110,14 +114,14 @@ private static void ProcessGenericType(StringBuilder builder, Type type, Type[] int offset = 0; if (type.IsNested) { - offset = type.DeclaringType.GetGenericArguments().Length; + offset = type.DeclaringType!.GetGenericArguments().Length; } if (options.FullName) { if (type.IsNested) { - ProcessGenericType(builder, type.DeclaringType, genericArguments, offset, options); + ProcessGenericType(builder, type.DeclaringType!, genericArguments, offset, options); builder.Append(options.NestedTypeDelimiter); } else if (!string.IsNullOrEmpty(type.Namespace)) diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj b/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj index 412c9bef97e48f..58552c053317fa 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj +++ b/src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj @@ -4,6 +4,7 @@ $(NetCoreAppCurrent);net461;netstandard2.0;netstandard2.1 False + Annotations diff --git a/src/libraries/Microsoft.Extensions.Http/src/Microsoft.Extensions.Http.csproj b/src/libraries/Microsoft.Extensions.Http/src/Microsoft.Extensions.Http.csproj index 6de909a45f7eaf..f8382783997e59 100644 --- a/src/libraries/Microsoft.Extensions.Http/src/Microsoft.Extensions.Http.csproj +++ b/src/libraries/Microsoft.Extensions.Http/src/Microsoft.Extensions.Http.csproj @@ -3,6 +3,7 @@ netstandard2.0;net461 true + Annotations diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs index 6c492ac9bd9cfc..e2d403bc7b38cf 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs @@ -10,11 +10,11 @@ public readonly partial struct EventId { private readonly object _dummy; private readonly int _dummyPrimitive; - public EventId(int id, string name = null) { throw null; } + public EventId(int id, string? name = null) { throw null; } public int Id { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public bool Equals(Microsoft.Extensions.Logging.EventId other) { throw null; } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(Microsoft.Extensions.Logging.EventId left, Microsoft.Extensions.Logging.EventId right) { throw null; } public static implicit operator Microsoft.Extensions.Logging.EventId (int i) { throw null; } @@ -23,14 +23,14 @@ public readonly partial struct EventId } public partial interface IExternalScopeProvider { - void ForEachScope(System.Action callback, TState state); - System.IDisposable Push(object state); + void ForEachScope(System.Action callback, TState state); + System.IDisposable Push(object? state); } public partial interface ILogger { System.IDisposable BeginScope(TState state); bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel); - void Log(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception exception, System.Func formatter); + void Log(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception? exception, System.Func formatter); } public partial interface ILoggerFactory : System.IDisposable { @@ -50,41 +50,41 @@ public partial interface ISupportExternalScope } public static partial class LoggerExtensions { - public static System.IDisposable BeginScope(this Microsoft.Extensions.Logging.ILogger logger, string messageFormat, params object[] args) { throw null; } - public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, System.Exception exception, string message, params object[] args) { } - public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string message, params object[] args) { } - public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, System.Exception exception, string message, params object[] args) { } - public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, string message, params object[] args) { } - public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception exception, string message, params object[] args) { } - public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string message, params object[] args) { } - public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, string message, params object[] args) { } - public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, string message, params object[] args) { } - public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception exception, string message, params object[] args) { } - public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string message, params object[] args) { } - public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, string message, params object[] args) { } - public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, string message, params object[] args) { } - public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception exception, string message, params object[] args) { } - public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string message, params object[] args) { } - public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, string message, params object[] args) { } - public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, string message, params object[] args) { } - public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception exception, string message, params object[] args) { } - public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string message, params object[] args) { } - public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, string message, params object[] args) { } - public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, string message, params object[] args) { } - public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception exception, string message, params object[] args) { } - public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string message, params object[] args) { } - public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, string message, params object[] args) { } - public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, string message, params object[] args) { } - public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception exception, string message, params object[] args) { } - public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string message, params object[] args) { } - public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, string message, params object[] args) { } - public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, string message, params object[] args) { } + public static System.IDisposable BeginScope(this Microsoft.Extensions.Logging.ILogger logger, string messageFormat, params object?[] args) { throw null; } + public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, System.Exception? exception, string? message, params object?[] args) { } + public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args) { } + public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, System.Exception? exception, string? message, params object?[] args) { } + public static void Log(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.LogLevel logLevel, string? message, params object?[] args) { } + public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception? exception, string? message, params object?[] args) { } + public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args) { } + public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, System.Exception? exception, string? message, params object?[] args) { } + public static void LogCritical(this Microsoft.Extensions.Logging.ILogger logger, string? message, params object?[] args) { } + public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception? exception, string? message, params object?[] args) { } + public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args) { } + public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, System.Exception? exception, string? message, params object?[] args) { } + public static void LogDebug(this Microsoft.Extensions.Logging.ILogger logger, string? message, params object?[] args) { } + public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception? exception, string? message, params object?[] args) { } + public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args) { } + public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, System.Exception? exception, string? message, params object?[] args) { } + public static void LogError(this Microsoft.Extensions.Logging.ILogger logger, string? message, params object?[] args) { } + public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception? exception, string? message, params object?[] args) { } + public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args) { } + public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, System.Exception? exception, string? message, params object?[] args) { } + public static void LogInformation(this Microsoft.Extensions.Logging.ILogger logger, string? message, params object?[] args) { } + public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception? exception, string? message, params object?[] args) { } + public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args) { } + public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, System.Exception? exception, string? message, params object?[] args) { } + public static void LogTrace(this Microsoft.Extensions.Logging.ILogger logger, string? message, params object?[] args) { } + public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, System.Exception? exception, string? message, params object?[] args) { } + public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args) { } + public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, System.Exception? exception, string? message, params object?[] args) { } + public static void LogWarning(this Microsoft.Extensions.Logging.ILogger logger, string? message, params object?[] args) { } } public partial class LoggerExternalScopeProvider : Microsoft.Extensions.Logging.IExternalScopeProvider { public LoggerExternalScopeProvider() { } - public void ForEachScope(System.Action callback, TState state) { } - public System.IDisposable Push(object state) { throw null; } + public void ForEachScope(System.Action callback, TState state) { } + public System.IDisposable Push(object? state) { throw null; } } public static partial class LoggerFactoryExtensions { @@ -93,7 +93,7 @@ public static partial class LoggerFactoryExtensions } public static partial class LoggerMessage { - public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } + public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } public static System.Func DefineScope(string formatString) { throw null; } public static System.Func DefineScope(string formatString) { throw null; } public static System.Func DefineScope(string formatString) { throw null; } @@ -101,12 +101,12 @@ public static partial class LoggerMessage public static System.Func DefineScope(string formatString) { throw null; } public static System.Func DefineScope(string formatString) { throw null; } public static System.Func DefineScope(string formatString) { throw null; } - public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } - public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } - public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } - public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } - public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } - public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } + public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } + public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } + public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } + public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } + public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } + public static System.Action Define(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; } } public partial class Logger : Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.ILogger { @@ -133,11 +133,11 @@ public readonly partial struct LogEntry private readonly TState _State_k__BackingField; private readonly object _dummy; private readonly int _dummyPrimitive; - public LogEntry(Microsoft.Extensions.Logging.LogLevel logLevel, string category, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception exception, System.Func formatter) { throw null; } + public LogEntry(Microsoft.Extensions.Logging.LogLevel logLevel, string category, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception? exception, System.Func formatter) { throw null; } public string Category { get { throw null; } } public Microsoft.Extensions.Logging.EventId EventId { get { throw null; } } - public System.Exception Exception { get { throw null; } } - public System.Func Formatter { get { throw null; } } + public System.Exception? Exception { get { throw null; } } + public System.Func? Formatter { get { throw null; } } public Microsoft.Extensions.Logging.LogLevel LogLevel { get { throw null; } } public TState State { get { throw null; } } } @@ -147,7 +147,7 @@ internal NullLogger() { } public static Microsoft.Extensions.Logging.Abstractions.NullLogger Instance { get { throw null; } } public System.IDisposable BeginScope(TState state) { throw null; } public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { throw null; } - public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception exception, System.Func formatter) { } + public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception? exception, System.Func formatter) { } } public partial class NullLoggerFactory : Microsoft.Extensions.Logging.ILoggerFactory, System.IDisposable { @@ -170,6 +170,6 @@ public partial class NullLogger : Microsoft.Extensions.Logging.ILogger, Micro public NullLogger() { } public System.IDisposable BeginScope(TState state) { throw null; } public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { throw null; } - public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception exception, System.Func formatter) { } + public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception? exception, System.Func formatter) { } } } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs index 5c7d7de2b9d367..7e031c5ec5f6b4 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs @@ -44,7 +44,7 @@ public static implicit operator EventId(int i) /// /// The numeric identifier for this event. /// The name of this event. - public EventId(int id, string name = null) + public EventId(int id, string? name = null) { Id = id; Name = name; @@ -58,7 +58,7 @@ public EventId(int id, string name = null) /// /// Gets the name of this event. /// - public string Name { get; } + public string? Name { get; } /// public override string ToString() @@ -77,7 +77,7 @@ public bool Equals(EventId other) } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is null) { diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs index ad0bde9b6fb958..4ee37937aa5148 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs @@ -10,23 +10,23 @@ namespace Microsoft.Extensions.Logging { /// - /// LogValues to enable formatting options supported by . + /// LogValues to enable formatting options supported by . /// This also enables using {NamedformatItem} in the format string. /// - internal readonly struct FormattedLogValues : IReadOnlyList> + internal readonly struct FormattedLogValues : IReadOnlyList> { internal const int MaxCachedFormatters = 1024; private const string NullFormat = "[null]"; private static int _count; private static ConcurrentDictionary _formatters = new ConcurrentDictionary(); - private readonly LogValuesFormatter _formatter; - private readonly object[] _values; + private readonly LogValuesFormatter? _formatter; + private readonly object?[]? _values; private readonly string _originalMessage; // for testing purposes - internal LogValuesFormatter Formatter => _formatter; + internal LogValuesFormatter? Formatter => _formatter; - public FormattedLogValues(string format, params object[] values) + public FormattedLogValues(string? format, params object?[]? values) { if (values != null && values.Length != 0 && format != null) { @@ -55,7 +55,7 @@ public FormattedLogValues(string format, params object[] values) _values = values; } - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { @@ -66,10 +66,10 @@ public KeyValuePair this[int index] if (index == Count - 1) { - return new KeyValuePair ("{OriginalFormat}", _originalMessage); + return new KeyValuePair ("{OriginalFormat}", _originalMessage); } - return _formatter.GetValue(_values, index); + return _formatter!.GetValue(_values!, index); } } @@ -86,7 +86,7 @@ public int Count } } - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IExternalScopeProvider.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IExternalScopeProvider.cs index 85e8d9cf29a831..20855aa043c0aa 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IExternalScopeProvider.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IExternalScopeProvider.cs @@ -17,13 +17,13 @@ public interface IExternalScopeProvider /// The callback to be executed for every scope object /// The state object to be passed into the callback /// The type of state to accept. - void ForEachScope(Action callback, TState state); + void ForEachScope(Action callback, TState state); /// /// Adds scope object to the list /// /// The scope object /// The token that removes scope on dispose. - IDisposable Push(object state); + IDisposable Push(object? state); } } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/ILogger.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/ILogger.cs index d7164852b48375..15c70258276473 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/ILogger.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/ILogger.cs @@ -20,7 +20,7 @@ public interface ILogger /// The exception related to this entry. /// Function to create a message of the and . /// The type of the object to be written. - void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter); + void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter); /// /// Checks if the given is enabled. diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogEntry.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogEntry.cs index e0cab847a156f5..cebd054da91b77 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogEntry.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogEntry.cs @@ -19,7 +19,7 @@ public readonly struct LogEntry /// The state for which log is being written. /// The log exception. /// The formatter. - public LogEntry(LogLevel logLevel, string category, EventId eventId, TState state, Exception exception, Func formatter) + public LogEntry(LogLevel logLevel, string category, EventId eventId, TState state, Exception? exception, Func formatter) { LogLevel = logLevel; Category = category; @@ -52,11 +52,11 @@ public LogEntry(LogLevel logLevel, string category, EventId eventId, TState stat /// /// Gets the log exception /// - public Exception Exception { get; } + public Exception? Exception { get; } /// /// Gets the formatter /// - public Func Formatter { get; } + public Func? Formatter { get; } } } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs index 2368a18848465b..f9565145d666b1 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs @@ -128,7 +128,7 @@ private static int FindIndexOfAny(string format, char[] chars, int startIndex, i return findIndex == -1 ? endIndex : findIndex; } - public string Format(object[] values) + public string Format(object?[]? values) { if (values != null) { @@ -146,22 +146,22 @@ internal string Format() return _format; } - internal string Format(object arg0) + internal string Format(object? arg0) { return string.Format(CultureInfo.InvariantCulture, _format, FormatArgument(arg0)); } - internal string Format(object arg0, object arg1) + internal string Format(object? arg0, object? arg1) { return string.Format(CultureInfo.InvariantCulture, _format, FormatArgument(arg0), FormatArgument(arg1)); } - internal string Format(object arg0, object arg1, object arg2) + internal string Format(object? arg0, object? arg1, object? arg2) { return string.Format(CultureInfo.InvariantCulture, _format, FormatArgument(arg0), FormatArgument(arg1), FormatArgument(arg2)); } - public KeyValuePair GetValue(object[] values, int index) + public KeyValuePair GetValue(object?[] values, int index) { if (index < 0 || index > _valueNames.Count) { @@ -170,25 +170,25 @@ public KeyValuePair GetValue(object[] values, int index) if (_valueNames.Count > index) { - return new KeyValuePair(_valueNames[index], values[index]); + return new KeyValuePair(_valueNames[index], values[index]); } - return new KeyValuePair("{OriginalFormat}", OriginalFormat); + return new KeyValuePair("{OriginalFormat}", OriginalFormat); } - public IEnumerable> GetValues(object[] values) + public IEnumerable> GetValues(object[] values) { - var valueArray = new KeyValuePair[values.Length + 1]; + var valueArray = new KeyValuePair[values.Length + 1]; for (int index = 0; index != _valueNames.Count; ++index) { - valueArray[index] = new KeyValuePair(_valueNames[index], values[index]); + valueArray[index] = new KeyValuePair(_valueNames[index], values[index]); } - valueArray[valueArray.Length - 1] = new KeyValuePair("{OriginalFormat}", OriginalFormat); + valueArray[valueArray.Length - 1] = new KeyValuePair("{OriginalFormat}", OriginalFormat); return valueArray; } - private object FormatArgument(object value) + private object FormatArgument(object? value) { if (value == null) { diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExtensions.cs index 6f742843a5493b..4ef6c371e2b918 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExtensions.cs @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.Logging /// public static class LoggerExtensions { - private static readonly Func _messageFormatter = MessageFormatter; + private static readonly Func _messageFormatter = MessageFormatter; //------------------------------------------DEBUG------------------------------------------// @@ -23,7 +23,7 @@ public static class LoggerExtensions /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogDebug(0, exception, "Error while processing request from {Address}", address) - public static void LogDebug(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args) + public static void LogDebug(this ILogger logger, EventId eventId, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Debug, eventId, exception, message, args); } @@ -36,7 +36,7 @@ public static void LogDebug(this ILogger logger, EventId eventId, Exception exce /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogDebug(0, "Processing request from {Address}", address) - public static void LogDebug(this ILogger logger, EventId eventId, string message, params object[] args) + public static void LogDebug(this ILogger logger, EventId eventId, string? message, params object?[] args) { logger.Log(LogLevel.Debug, eventId, message, args); } @@ -49,7 +49,7 @@ public static void LogDebug(this ILogger logger, EventId eventId, string message /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogDebug(exception, "Error while processing request from {Address}", address) - public static void LogDebug(this ILogger logger, Exception exception, string message, params object[] args) + public static void LogDebug(this ILogger logger, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Debug, exception, message, args); } @@ -61,7 +61,7 @@ public static void LogDebug(this ILogger logger, Exception exception, string mes /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogDebug("Processing request from {Address}", address) - public static void LogDebug(this ILogger logger, string message, params object[] args) + public static void LogDebug(this ILogger logger, string? message, params object?[] args) { logger.Log(LogLevel.Debug, message, args); } @@ -77,7 +77,7 @@ public static void LogDebug(this ILogger logger, string message, params object[] /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogTrace(0, exception, "Error while processing request from {Address}", address) - public static void LogTrace(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args) + public static void LogTrace(this ILogger logger, EventId eventId, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Trace, eventId, exception, message, args); } @@ -90,7 +90,7 @@ public static void LogTrace(this ILogger logger, EventId eventId, Exception exce /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogTrace(0, "Processing request from {Address}", address) - public static void LogTrace(this ILogger logger, EventId eventId, string message, params object[] args) + public static void LogTrace(this ILogger logger, EventId eventId, string? message, params object?[] args) { logger.Log(LogLevel.Trace, eventId, message, args); } @@ -103,7 +103,7 @@ public static void LogTrace(this ILogger logger, EventId eventId, string message /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogTrace(exception, "Error while processing request from {Address}", address) - public static void LogTrace(this ILogger logger, Exception exception, string message, params object[] args) + public static void LogTrace(this ILogger logger, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Trace, exception, message, args); } @@ -115,7 +115,7 @@ public static void LogTrace(this ILogger logger, Exception exception, string mes /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogTrace("Processing request from {Address}", address) - public static void LogTrace(this ILogger logger, string message, params object[] args) + public static void LogTrace(this ILogger logger, string? message, params object?[] args) { logger.Log(LogLevel.Trace, message, args); } @@ -131,7 +131,7 @@ public static void LogTrace(this ILogger logger, string message, params object[] /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogInformation(0, exception, "Error while processing request from {Address}", address) - public static void LogInformation(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args) + public static void LogInformation(this ILogger logger, EventId eventId, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Information, eventId, exception, message, args); } @@ -144,7 +144,7 @@ public static void LogInformation(this ILogger logger, EventId eventId, Exceptio /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogInformation(0, "Processing request from {Address}", address) - public static void LogInformation(this ILogger logger, EventId eventId, string message, params object[] args) + public static void LogInformation(this ILogger logger, EventId eventId, string? message, params object?[] args) { logger.Log(LogLevel.Information, eventId, message, args); } @@ -157,7 +157,7 @@ public static void LogInformation(this ILogger logger, EventId eventId, string m /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogInformation(exception, "Error while processing request from {Address}", address) - public static void LogInformation(this ILogger logger, Exception exception, string message, params object[] args) + public static void LogInformation(this ILogger logger, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Information, exception, message, args); } @@ -169,7 +169,7 @@ public static void LogInformation(this ILogger logger, Exception exception, stri /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogInformation("Processing request from {Address}", address) - public static void LogInformation(this ILogger logger, string message, params object[] args) + public static void LogInformation(this ILogger logger, string? message, params object?[] args) { logger.Log(LogLevel.Information, message, args); } @@ -185,7 +185,7 @@ public static void LogInformation(this ILogger logger, string message, params ob /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogWarning(0, exception, "Error while processing request from {Address}", address) - public static void LogWarning(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args) + public static void LogWarning(this ILogger logger, EventId eventId, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Warning, eventId, exception, message, args); } @@ -198,7 +198,7 @@ public static void LogWarning(this ILogger logger, EventId eventId, Exception ex /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogWarning(0, "Processing request from {Address}", address) - public static void LogWarning(this ILogger logger, EventId eventId, string message, params object[] args) + public static void LogWarning(this ILogger logger, EventId eventId, string? message, params object?[] args) { logger.Log(LogLevel.Warning, eventId, message, args); } @@ -211,7 +211,7 @@ public static void LogWarning(this ILogger logger, EventId eventId, string messa /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogWarning(exception, "Error while processing request from {Address}", address) - public static void LogWarning(this ILogger logger, Exception exception, string message, params object[] args) + public static void LogWarning(this ILogger logger, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Warning, exception, message, args); } @@ -223,7 +223,7 @@ public static void LogWarning(this ILogger logger, Exception exception, string m /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogWarning("Processing request from {Address}", address) - public static void LogWarning(this ILogger logger, string message, params object[] args) + public static void LogWarning(this ILogger logger, string? message, params object?[] args) { logger.Log(LogLevel.Warning, message, args); } @@ -239,7 +239,7 @@ public static void LogWarning(this ILogger logger, string message, params object /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogError(0, exception, "Error while processing request from {Address}", address) - public static void LogError(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args) + public static void LogError(this ILogger logger, EventId eventId, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Error, eventId, exception, message, args); } @@ -252,7 +252,7 @@ public static void LogError(this ILogger logger, EventId eventId, Exception exce /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogError(0, "Processing request from {Address}", address) - public static void LogError(this ILogger logger, EventId eventId, string message, params object[] args) + public static void LogError(this ILogger logger, EventId eventId, string? message, params object?[] args) { logger.Log(LogLevel.Error, eventId, message, args); } @@ -265,7 +265,7 @@ public static void LogError(this ILogger logger, EventId eventId, string message /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogError(exception, "Error while processing request from {Address}", address) - public static void LogError(this ILogger logger, Exception exception, string message, params object[] args) + public static void LogError(this ILogger logger, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Error, exception, message, args); } @@ -277,7 +277,7 @@ public static void LogError(this ILogger logger, Exception exception, string mes /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogError("Processing request from {Address}", address) - public static void LogError(this ILogger logger, string message, params object[] args) + public static void LogError(this ILogger logger, string? message, params object?[] args) { logger.Log(LogLevel.Error, message, args); } @@ -293,7 +293,7 @@ public static void LogError(this ILogger logger, string message, params object[] /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogCritical(0, exception, "Error while processing request from {Address}", address) - public static void LogCritical(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args) + public static void LogCritical(this ILogger logger, EventId eventId, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Critical, eventId, exception, message, args); } @@ -306,7 +306,7 @@ public static void LogCritical(this ILogger logger, EventId eventId, Exception e /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogCritical(0, "Processing request from {Address}", address) - public static void LogCritical(this ILogger logger, EventId eventId, string message, params object[] args) + public static void LogCritical(this ILogger logger, EventId eventId, string? message, params object?[] args) { logger.Log(LogLevel.Critical, eventId, message, args); } @@ -319,7 +319,7 @@ public static void LogCritical(this ILogger logger, EventId eventId, string mess /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogCritical(exception, "Error while processing request from {Address}", address) - public static void LogCritical(this ILogger logger, Exception exception, string message, params object[] args) + public static void LogCritical(this ILogger logger, Exception? exception, string? message, params object?[] args) { logger.Log(LogLevel.Critical, exception, message, args); } @@ -331,7 +331,7 @@ public static void LogCritical(this ILogger logger, Exception exception, string /// Format string of the log message in message template format. Example: "User {User} logged in from {Address}" /// An object array that contains zero or more objects to format. /// logger.LogCritical("Processing request from {Address}", address) - public static void LogCritical(this ILogger logger, string message, params object[] args) + public static void LogCritical(this ILogger logger, string? message, params object?[] args) { logger.Log(LogLevel.Critical, message, args); } @@ -343,7 +343,7 @@ public static void LogCritical(this ILogger logger, string message, params objec /// Entry will be written on this level. /// Format string of the log message. /// An object array that contains zero or more objects to format. - public static void Log(this ILogger logger, LogLevel logLevel, string message, params object[] args) + public static void Log(this ILogger logger, LogLevel logLevel, string? message, params object?[] args) { logger.Log(logLevel, 0, null, message, args); } @@ -356,7 +356,7 @@ public static void Log(this ILogger logger, LogLevel logLevel, string message, p /// The event id associated with the log. /// Format string of the log message. /// An object array that contains zero or more objects to format. - public static void Log(this ILogger logger, LogLevel logLevel, EventId eventId, string message, params object[] args) + public static void Log(this ILogger logger, LogLevel logLevel, EventId eventId, string? message, params object?[] args) { logger.Log(logLevel, eventId, null, message, args); } @@ -369,7 +369,7 @@ public static void Log(this ILogger logger, LogLevel logLevel, EventId eventId, /// The exception to log. /// Format string of the log message. /// An object array that contains zero or more objects to format. - public static void Log(this ILogger logger, LogLevel logLevel, Exception exception, string message, params object[] args) + public static void Log(this ILogger logger, LogLevel logLevel, Exception? exception, string? message, params object?[] args) { logger.Log(logLevel, 0, exception, message, args); } @@ -383,7 +383,7 @@ public static void Log(this ILogger logger, LogLevel logLevel, Exception excepti /// The exception to log. /// Format string of the log message. /// An object array that contains zero or more objects to format. - public static void Log(this ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, string message, params object[] args) + public static void Log(this ILogger logger, LogLevel logLevel, EventId eventId, Exception? exception, string? message, params object?[] args) { if (logger == null) { @@ -410,7 +410,7 @@ public static void Log(this ILogger logger, LogLevel logLevel, EventId eventId, public static IDisposable BeginScope( this ILogger logger, string messageFormat, - params object[] args) + params object?[] args) { if (logger == null) { @@ -422,7 +422,7 @@ public static IDisposable BeginScope( //------------------------------------------HELPERS------------------------------------------// - private static string MessageFormatter(FormattedLogValues state, Exception error) + private static string MessageFormatter(FormattedLogValues state, Exception? error) { return state.ToString(); } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExternalScopeProvider.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExternalScopeProvider.cs index bd6980a963b1f4..0afed527c11bc4 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExternalScopeProvider.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExternalScopeProvider.cs @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Logging /// public class LoggerExternalScopeProvider : IExternalScopeProvider { - private readonly AsyncLocal _currentScope = new AsyncLocal(); + private readonly AsyncLocal _currentScope = new AsyncLocal(); /// /// Creates a new . @@ -20,9 +20,9 @@ public LoggerExternalScopeProvider() { } /// - public void ForEachScope(Action callback, TState state) + public void ForEachScope(Action callback, TState state) { - void Report(Scope current) + void Report(Scope? current) { if (current == null) { @@ -35,9 +35,9 @@ void Report(Scope current) } /// - public IDisposable Push(object state) + public IDisposable Push(object? state) { - Scope parent = _currentScope.Value; + Scope? parent = _currentScope.Value; var newScope = new Scope(this, state, parent); _currentScope.Value = newScope; @@ -49,18 +49,18 @@ private class Scope : IDisposable private readonly LoggerExternalScopeProvider _provider; private bool _isDisposed; - internal Scope(LoggerExternalScopeProvider provider, object state, Scope parent) + internal Scope(LoggerExternalScopeProvider provider, object? state, Scope? parent) { _provider = provider; State = state; Parent = parent; } - public Scope Parent { get; } + public Scope? Parent { get; } - public object State { get; } + public object? State { get; } - public override string ToString() + public override string? ToString() { return State?.ToString(); } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerMessage.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerMessage.cs index 27c7b5b75031c8..2d9fa977ee7255 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerMessage.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerMessage.cs @@ -127,7 +127,7 @@ public static Func DefineScopeThe event id /// The named format string /// A delegate which when invoked creates a log message. - public static Action Define(LogLevel logLevel, EventId eventId, string formatString) + public static Action Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 0); @@ -148,11 +148,11 @@ public static Action Define(LogLevel logLevel, EventId event /// The event id /// The named format string /// A delegate which when invoked creates a log message. - public static Action Define(LogLevel logLevel, EventId eventId, string formatString) + public static Action Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 1); - void Log(ILogger logger, T1 arg1, Exception exception) + void Log(ILogger logger, T1 arg1, Exception? exception) { logger.Log(logLevel, eventId, new LogValues(formatter, arg1), exception, LogValues.Callback); } @@ -175,11 +175,11 @@ void Log(ILogger logger, T1 arg1, Exception exception) /// The event id /// The named format string /// A delegate which when invoked creates a log message. - public static Action Define(LogLevel logLevel, EventId eventId, string formatString) + public static Action Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 2); - void Log(ILogger logger, T1 arg1, T2 arg2, Exception exception) + void Log(ILogger logger, T1 arg1, T2 arg2, Exception? exception) { logger.Log(logLevel, eventId, new LogValues(formatter, arg1, arg2), exception, LogValues.Callback); } @@ -203,11 +203,11 @@ void Log(ILogger logger, T1 arg1, T2 arg2, Exception exception) /// The event id /// The named format string /// A delegate which when invoked creates a log message. - public static Action Define(LogLevel logLevel, EventId eventId, string formatString) + public static Action Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 3); - void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, Exception exception) + void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, Exception? exception) { logger.Log(logLevel, eventId, new LogValues(formatter, arg1, arg2, arg3), exception, LogValues.Callback); } @@ -232,11 +232,11 @@ void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, Exception exception) /// The event id /// The named format string /// A delegate which when invoked creates a log message. - public static Action Define(LogLevel logLevel, EventId eventId, string formatString) + public static Action Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 4); - void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Exception exception) + void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Exception? exception) { logger.Log(logLevel, eventId, new LogValues(formatter, arg1, arg2, arg3, arg4), exception, LogValues.Callback); } @@ -262,7 +262,7 @@ void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Exception exception /// The event id /// The named format string /// A delegate which when invoked creates a log message. - public static Action Define(LogLevel logLevel, EventId eventId, string formatString) + public static Action Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 5); @@ -288,7 +288,7 @@ public static Action DefineThe event id /// The named format string /// A delegate which when invoked creates a log message. - public static Action Define(LogLevel logLevel, EventId eventId, string formatString) + public static Action Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 6); @@ -315,9 +315,9 @@ private static LogValuesFormatter CreateLogValuesFormatter(string formatString, return logValuesFormatter; } - private readonly struct LogValues : IReadOnlyList> + private readonly struct LogValues : IReadOnlyList> { - public static readonly Func Callback = (state, exception) => state.ToString(); + public static readonly Func Callback = (state, exception) => state.ToString(); private readonly LogValuesFormatter _formatter; @@ -326,13 +326,13 @@ public LogValues(LogValuesFormatter formatter) _formatter = formatter; } - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { if (index == 0) { - return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); + return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); } throw new IndexOutOfRangeException(nameof(index)); } @@ -340,7 +340,7 @@ public KeyValuePair this[int index] public int Count => 1; - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { yield return this[0]; } @@ -353,9 +353,9 @@ IEnumerator IEnumerable.GetEnumerator() } } - private readonly struct LogValues : IReadOnlyList> + private readonly struct LogValues : IReadOnlyList> { - public static readonly Func, Exception, string> Callback = (state, exception) => state.ToString(); + public static readonly Func, Exception?, string> Callback = (state, exception) => state.ToString(); private readonly LogValuesFormatter _formatter; private readonly T0 _value0; @@ -366,16 +366,16 @@ public LogValues(LogValuesFormatter formatter, T0 value0) _value0 = value0; } - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { switch (index) { case 0: - return new KeyValuePair(_formatter.ValueNames[0], _value0); + return new KeyValuePair(_formatter.ValueNames[0], _value0); case 1: - return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); + return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); default: throw new IndexOutOfRangeException(nameof(index)); } @@ -384,7 +384,7 @@ public KeyValuePair this[int index] public int Count => 2; - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { @@ -401,9 +401,9 @@ IEnumerator IEnumerable.GetEnumerator() } } - private readonly struct LogValues : IReadOnlyList> + private readonly struct LogValues : IReadOnlyList> { - public static readonly Func, Exception, string> Callback = (state, exception) => state.ToString(); + public static readonly Func, Exception?, string> Callback = (state, exception) => state.ToString(); private readonly LogValuesFormatter _formatter; private readonly T0 _value0; @@ -416,18 +416,18 @@ public LogValues(LogValuesFormatter formatter, T0 value0, T1 value1) _value1 = value1; } - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { switch (index) { case 0: - return new KeyValuePair(_formatter.ValueNames[0], _value0); + return new KeyValuePair(_formatter.ValueNames[0], _value0); case 1: - return new KeyValuePair(_formatter.ValueNames[1], _value1); + return new KeyValuePair(_formatter.ValueNames[1], _value1); case 2: - return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); + return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); default: throw new IndexOutOfRangeException(nameof(index)); } @@ -436,7 +436,7 @@ public KeyValuePair this[int index] public int Count => 3; - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { @@ -452,9 +452,9 @@ IEnumerator IEnumerable.GetEnumerator() } } - private readonly struct LogValues : IReadOnlyList> + private readonly struct LogValues : IReadOnlyList> { - public static readonly Func, Exception, string> Callback = (state, exception) => state.ToString(); + public static readonly Func, Exception?, string> Callback = (state, exception) => state.ToString(); private readonly LogValuesFormatter _formatter; private readonly T0 _value0; @@ -463,20 +463,20 @@ IEnumerator IEnumerable.GetEnumerator() public int Count => 4; - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { switch (index) { case 0: - return new KeyValuePair(_formatter.ValueNames[0], _value0); + return new KeyValuePair(_formatter.ValueNames[0], _value0); case 1: - return new KeyValuePair(_formatter.ValueNames[1], _value1); + return new KeyValuePair(_formatter.ValueNames[1], _value1); case 2: - return new KeyValuePair(_formatter.ValueNames[2], _value2); + return new KeyValuePair(_formatter.ValueNames[2], _value2); case 3: - return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); + return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); default: throw new IndexOutOfRangeException(nameof(index)); } @@ -493,7 +493,7 @@ public LogValues(LogValuesFormatter formatter, T0 value0, T1 value1, T2 value2) public override string ToString() => _formatter.Format(_value0, _value1, _value2); - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { @@ -507,9 +507,9 @@ IEnumerator IEnumerable.GetEnumerator() } } - private readonly struct LogValues : IReadOnlyList> + private readonly struct LogValues : IReadOnlyList> { - public static readonly Func, Exception, string> Callback = (state, exception) => state.ToString(); + public static readonly Func, Exception?, string> Callback = (state, exception) => state.ToString(); private readonly LogValuesFormatter _formatter; private readonly T0 _value0; @@ -519,22 +519,22 @@ IEnumerator IEnumerable.GetEnumerator() public int Count => 5; - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { switch (index) { case 0: - return new KeyValuePair(_formatter.ValueNames[0], _value0); + return new KeyValuePair(_formatter.ValueNames[0], _value0); case 1: - return new KeyValuePair(_formatter.ValueNames[1], _value1); + return new KeyValuePair(_formatter.ValueNames[1], _value1); case 2: - return new KeyValuePair(_formatter.ValueNames[2], _value2); + return new KeyValuePair(_formatter.ValueNames[2], _value2); case 3: - return new KeyValuePair(_formatter.ValueNames[3], _value3); + return new KeyValuePair(_formatter.ValueNames[3], _value3); case 4: - return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); + return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); default: throw new IndexOutOfRangeException(nameof(index)); } @@ -550,11 +550,11 @@ public LogValues(LogValuesFormatter formatter, T0 value0, T1 value1, T2 value2, _value3 = value3; } - private object[] ToArray() => new object[] { _value0, _value1, _value2, _value3 }; + private object?[] ToArray() => new object?[] { _value0, _value1, _value2, _value3 }; public override string ToString() => _formatter.Format(ToArray()); - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { @@ -568,9 +568,9 @@ IEnumerator IEnumerable.GetEnumerator() } } - private readonly struct LogValues : IReadOnlyList> + private readonly struct LogValues : IReadOnlyList> { - public static readonly Func, Exception, string> Callback = (state, exception) => state.ToString(); + public static readonly Func, Exception?, string> Callback = (state, exception) => state.ToString(); private readonly LogValuesFormatter _formatter; private readonly T0 _value0; @@ -581,24 +581,24 @@ IEnumerator IEnumerable.GetEnumerator() public int Count => 6; - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { switch (index) { case 0: - return new KeyValuePair(_formatter.ValueNames[0], _value0); + return new KeyValuePair(_formatter.ValueNames[0], _value0); case 1: - return new KeyValuePair(_formatter.ValueNames[1], _value1); + return new KeyValuePair(_formatter.ValueNames[1], _value1); case 2: - return new KeyValuePair(_formatter.ValueNames[2], _value2); + return new KeyValuePair(_formatter.ValueNames[2], _value2); case 3: - return new KeyValuePair(_formatter.ValueNames[3], _value3); + return new KeyValuePair(_formatter.ValueNames[3], _value3); case 4: - return new KeyValuePair(_formatter.ValueNames[4], _value4); + return new KeyValuePair(_formatter.ValueNames[4], _value4); case 5: - return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); + return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); default: throw new IndexOutOfRangeException(nameof(index)); } @@ -615,11 +615,11 @@ public LogValues(LogValuesFormatter formatter, T0 value0, T1 value1, T2 value2, _value4 = value4; } - private object[] ToArray() => new object[] { _value0, _value1, _value2, _value3, _value4 }; + private object?[] ToArray() => new object?[] { _value0, _value1, _value2, _value3, _value4 }; public override string ToString() => _formatter.Format(ToArray()); - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { @@ -633,9 +633,9 @@ IEnumerator IEnumerable.GetEnumerator() } } - private readonly struct LogValues : IReadOnlyList> + private readonly struct LogValues : IReadOnlyList> { - public static readonly Func, Exception, string> Callback = (state, exception) => state.ToString(); + public static readonly Func, Exception?, string> Callback = (state, exception) => state.ToString(); private readonly LogValuesFormatter _formatter; private readonly T0 _value0; @@ -647,26 +647,26 @@ IEnumerator IEnumerable.GetEnumerator() public int Count => 7; - public KeyValuePair this[int index] + public KeyValuePair this[int index] { get { switch (index) { case 0: - return new KeyValuePair(_formatter.ValueNames[0], _value0); + return new KeyValuePair(_formatter.ValueNames[0], _value0); case 1: - return new KeyValuePair(_formatter.ValueNames[1], _value1); + return new KeyValuePair(_formatter.ValueNames[1], _value1); case 2: - return new KeyValuePair(_formatter.ValueNames[2], _value2); + return new KeyValuePair(_formatter.ValueNames[2], _value2); case 3: - return new KeyValuePair(_formatter.ValueNames[3], _value3); + return new KeyValuePair(_formatter.ValueNames[3], _value3); case 4: - return new KeyValuePair(_formatter.ValueNames[4], _value4); + return new KeyValuePair(_formatter.ValueNames[4], _value4); case 5: - return new KeyValuePair(_formatter.ValueNames[5], _value5); + return new KeyValuePair(_formatter.ValueNames[5], _value5); case 6: - return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); + return new KeyValuePair("{OriginalFormat}", _formatter.OriginalFormat); default: throw new IndexOutOfRangeException(nameof(index)); } @@ -684,11 +684,11 @@ public LogValues(LogValuesFormatter formatter, T0 value0, T1 value1, T2 value2, _value5 = value5; } - private object[] ToArray() => new object[] { _value0, _value1, _value2, _value3, _value4, _value5 }; + private object?[] ToArray() => new object?[] { _value0, _value1, _value2, _value3, _value4, _value5 }; public override string ToString() => _formatter.Format(ToArray()); - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerT.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerT.cs index 59f2f043cd181c..bea9a8bdeff700 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerT.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerT.cs @@ -42,7 +42,7 @@ bool ILogger.IsEnabled(LogLevel logLevel) } /// - void ILogger.Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + void ILogger.Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj index 457b3e9b8c7c7e..f110d08801ab1c 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj @@ -1,9 +1,13 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 + true true true + + false + enable diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLogger.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLogger.cs index f8bdacdc112d89..694ba8de9b1f6e 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLogger.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLogger.cs @@ -32,7 +32,7 @@ public bool IsEnabled(LogLevel logLevel) } /// - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { } } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLoggerT.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLoggerT.cs index 8e3a118575f359..1d228a33669f9b 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLoggerT.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLoggerT.cs @@ -30,8 +30,8 @@ public void Log( LogLevel logLevel, EventId eventId, TState state, - Exception exception, - Func formatter) + Exception? exception, + Func formatter) { }