Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Group 4] Enable nullable annotations for Microsoft.Extensions.Logging.EventLog #67200

Merged
merged 1 commit into from
Apr 1, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.Extensions.Logging.EventLog
public partial class EventLogLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider, Microsoft.Extensions.Logging.ISupportExternalScope, System.IDisposable
{
public EventLogLoggerProvider() { }
public EventLogLoggerProvider(Microsoft.Extensions.Logging.EventLog.EventLogSettings settings) { }
public EventLogLoggerProvider(Microsoft.Extensions.Logging.EventLog.EventLogSettings? settings) { }
public EventLogLoggerProvider(Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Logging.EventLog.EventLogSettings> options) { }
public Microsoft.Extensions.Logging.ILogger CreateLogger(string name) { throw null; }
public void Dispose() { }
Expand All @@ -28,9 +28,9 @@ public void SetScopeProvider(Microsoft.Extensions.Logging.IExternalScopeProvider
public partial class EventLogSettings
{
public EventLogSettings() { }
public System.Func<string, Microsoft.Extensions.Logging.LogLevel, bool> Filter { get { throw null; } set { } }
public string LogName { get { throw null; } set { } }
public string MachineName { get { throw null; } set { } }
public string SourceName { get { throw null; } set { } }
public System.Func<string, Microsoft.Extensions.Logging.LogLevel, bool>? Filter { get { throw null; } set { } }
public string? LogName { get { throw null; } set { } }
public string? MachineName { get { throw null; } set { } }
public string? SourceName { get { throw null; } set { } }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class EventLogLogger : ILogger
{
private readonly string _name;
private readonly EventLogSettings _settings;
private readonly IExternalScopeProvider _externalScopeProvider;
private readonly IExternalScopeProvider? _externalScopeProvider;

private const string ContinuationString = "...";
private readonly int _beginOrEndMessageSegmentSize;
Expand All @@ -27,7 +27,7 @@ internal sealed class EventLogLogger : ILogger
/// <param name="name">The name of the logger.</param>
/// <param name="settings">The <see cref="EventLogSettings"/>.</param>
/// <param name="externalScopeProvider">The <see cref="IExternalScopeProvider"/>.</param>
public EventLogLogger(string name!!, EventLogSettings settings!!, IExternalScopeProvider externalScopeProvider)
public EventLogLogger(string name!!, EventLogSettings settings!!, IExternalScopeProvider? externalScopeProvider)
{
_name = name;
_settings = settings;
Expand All @@ -48,7 +48,7 @@ public EventLogLogger(string name!!, EventLogSettings settings!!, IExternalScope
public IEventLog EventLog { get; }

/// <inheritdoc />
public IDisposable BeginScope<TState>(TState state)
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
{
return _externalScopeProvider?.Push(state);
}
Expand All @@ -65,8 +65,8 @@ public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
Exception? exception,
Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
{
Expand Down Expand Up @@ -129,7 +129,7 @@ private void WriteMessage(string message, EventLogEntryType eventLogEntryType, i
}

int startIndex = 0;
string messageSegment = null;
string? messageSegment = null;
while (true)
{
// Begin segment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class EventLogLoggerProvider : ILoggerProvider, ISupportExternalScope
{
internal readonly EventLogSettings _settings;

private IExternalScopeProvider _scopeProvider;
private IExternalScopeProvider? _scopeProvider;

/// <summary>
/// Initializes a new instance of the <see cref="EventLogLoggerProvider"/> class.
Expand All @@ -27,7 +27,7 @@ public EventLogLoggerProvider()
/// Initializes a new instance of the <see cref="EventLogLoggerProvider"/> class.
/// </summary>
/// <param name="settings">The <see cref="EventLogSettings"/>.</param>
public EventLogLoggerProvider(EventLogSettings settings)
public EventLogLoggerProvider(EventLogSettings? settings)
{
_settings = settings ?? new EventLogSettings();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ namespace Microsoft.Extensions.Logging.EventLog
/// </summary>
public class EventLogSettings
{
private IEventLog _eventLog;
private IEventLog? _eventLog;

/// <summary>
/// Name of the event log. If <c>null</c> or not specified, "Application" is the default.
/// </summary>
public string LogName { get; set; }
public string? LogName { get; set; }

/// <summary>
/// Name of the event log source. If <c>null</c> or not specified, ".NET Runtime" is the default.
/// </summary>
public string SourceName { get; set; }
public string? SourceName { get; set; }

/// <summary>
/// Name of the machine having the event log. If <c>null</c> or not specified, local machine is the default.
/// </summary>
public string MachineName { get; set; }
public string? MachineName { get; set; }

/// <summary>
/// The function used to filter events based on the log level.
/// </summary>
public Func<string, LogLevel, bool> Filter { get; set; }
public Func<string, LogLevel, bool>? Filter { get; set; }

internal IEventLog EventLog
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
<EnableDefaultItems>true</EnableDefaultItems>
<!-- Use targeting pack references instead of granular ones in the project file. -->
<DisableImplicitAssemblyReferences>false</DisableImplicitAssemblyReferences>
Expand Down