未验证 提交 a6d2b103 编写于 作者: M Maksym Koshovyi 提交者: GitHub

[Group 4] Enable nullable annotations for `Microsoft.Extensions.Logging.TraceSource` (#66892)

上级 ca8ddae2
......@@ -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() { }
}
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
......
......@@ -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>
......
......@@ -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))
{
......@@ -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;
}
......@@ -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);
}
......
......@@ -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);
......@@ -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;
......@@ -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))
{
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册