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.TraceSource #66892

Merged
merged 5 commits into from
Mar 25, 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 @@ -20,7 +20,7 @@ namespace Microsoft.Extensions.Logging.TraceSource
public partial class TraceSourceLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider, System.IDisposable
{
public TraceSourceLoggerProvider(System.Diagnostics.SourceSwitch rootSourceSwitch) { }
public TraceSourceLoggerProvider(System.Diagnostics.SourceSwitch rootSourceSwitch, System.Diagnostics.TraceListener rootTraceListener) { }
public TraceSourceLoggerProvider(System.Diagnostics.SourceSwitch rootSourceSwitch, System.Diagnostics.TraceListener? rootTraceListener) { }
public Microsoft.Extensions.Logging.ILogger CreateLogger(string name) { throw null; }
public void Dispose() { }
}
Expand Down
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public TraceSourceLogger(DiagnosticsTraceSource traceSource)
_traceSource = traceSource;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
{
Expand All @@ -36,7 +36,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except

if (exception != null)
{
string exceptionDelimiter = string.IsNullOrEmpty(message) ? string.Empty : " " ;
string exceptionDelimiter = string.IsNullOrEmpty(message) ? string.Empty : " ";
message += exceptionDelimiter + exception;
}

Expand Down Expand Up @@ -70,7 +70,7 @@ private static TraceEventType GetEventType(LogLevel logLevel)
}
}

public IDisposable BeginScope<TState>(TState state)
public IDisposable BeginScope<TState>(TState state) where TState : notnull
{
return new TraceSourceScope(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.Logging.TraceSource
public class TraceSourceLoggerProvider : ILoggerProvider
{
private readonly SourceSwitch _rootSourceSwitch;
private readonly TraceListener _rootTraceListener;
private readonly TraceListener? _rootTraceListener;

private readonly ConcurrentDictionary<string, DiagnosticsTraceSource> _sources = new ConcurrentDictionary<string, DiagnosticsTraceSource>(StringComparer.OrdinalIgnoreCase);

Expand All @@ -35,7 +35,7 @@ public TraceSourceLoggerProvider(SourceSwitch rootSourceSwitch)
/// </summary>
/// <param name="rootSourceSwitch">The <see cref="SourceSwitch"/> to use.</param>
/// <param name="rootTraceListener">The <see cref="TraceListener"/> to use.</param>
public TraceSourceLoggerProvider(SourceSwitch rootSourceSwitch!!, TraceListener rootTraceListener)
public TraceSourceLoggerProvider(SourceSwitch rootSourceSwitch!!, TraceListener? rootTraceListener)
{
_rootSourceSwitch = rootSourceSwitch;
_rootTraceListener = rootTraceListener;
Expand All @@ -59,7 +59,7 @@ private DiagnosticsTraceSource GetOrAddTraceSource(string name)
private DiagnosticsTraceSource InitializeTraceSource(string traceSourceName)
{
var traceSource = new DiagnosticsTraceSource(traceSourceName);
string parentSourceName = ParentSourceName(traceSourceName);
string? parentSourceName = ParentSourceName(traceSourceName);

if (string.IsNullOrEmpty(parentSourceName))
{
Expand Down Expand Up @@ -92,7 +92,7 @@ private DiagnosticsTraceSource InitializeTraceSource(string traceSourceName)
return traceSource;
}

private static string ParentSourceName(string traceSourceName)
private static string? ParentSourceName(string traceSourceName)
{
int indexOfLastDot = traceSourceName.LastIndexOf('.');
return indexOfLastDot == -1 ? null : traceSourceName.Substring(0, indexOfLastDot);
Expand Down