Remove use of null-conditional operator for logger (#6579)
This commit is contained in:
parent
9077b38805
commit
bff78bdd11
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption
|
|||
|
||||
BCryptAlgorithmHandle algorithmHandle = null;
|
||||
|
||||
_logger?.OpeningCNGAlgorithmFromProviderWithChainingModeGCM(configuration.EncryptionAlgorithm, configuration.EncryptionAlgorithmProvider);
|
||||
_logger.OpeningCNGAlgorithmFromProviderWithChainingModeGCM(configuration.EncryptionAlgorithm, configuration.EncryptionAlgorithmProvider);
|
||||
// Special-case cached providers
|
||||
if (configuration.EncryptionAlgorithmProvider == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace System
|
||||
{
|
||||
|
|
@ -37,7 +38,7 @@ namespace System
|
|||
{
|
||||
// Compiler won't allow us to use static types as the type parameter
|
||||
// for the call to CreateLogger<T>, so we'll duplicate its logic here.
|
||||
return services?.GetService<ILoggerFactory>()?.CreateLogger(type.FullName);
|
||||
return services?.GetService<ILoggerFactory>()?.CreateLogger(type.FullName) ?? NullLogger.Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
{
|
||||
// It's OK for us to log the error, as we control the exception, and it doesn't contain
|
||||
// sensitive information.
|
||||
_logger?.ExceptionOccurredTryingToDecryptElement(ex);
|
||||
_logger.ExceptionOccurredTryingToDecryptElement(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
throw new ArgumentNullException(nameof(encryptedElement));
|
||||
}
|
||||
|
||||
_logger?.DecryptingSecretElementUsingWindowsDPAPI();
|
||||
_logger.DecryptingSecretElementUsingWindowsDPAPI();
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
{
|
||||
// It's OK for us to log the error, as we control the exception, and it doesn't contain
|
||||
// sensitive information.
|
||||
_logger?.ExceptionOccurredTryingToDecryptElement(ex);
|
||||
_logger.ExceptionOccurredTryingToDecryptElement(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
throw new ArgumentNullException(nameof(plaintextElement));
|
||||
}
|
||||
|
||||
_logger?.EncryptingUsingNullEncryptor();
|
||||
_logger.EncryptingUsingNullEncryptor();
|
||||
|
||||
// <unencryptedKey>
|
||||
// <!-- This key is not encrypted. -->
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ using Microsoft.Extensions.Configuration;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.StackTrace.Sources;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
|||
|
||||
private IServiceProvider _applicationServices;
|
||||
private ExceptionDispatchInfo _applicationServicesException;
|
||||
private ILogger _logger;
|
||||
private ILogger _logger = NullLogger.Instance;
|
||||
|
||||
private bool _stopped;
|
||||
private bool _startedServer;
|
||||
|
|
@ -317,7 +318,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
|||
}
|
||||
_stopped = true;
|
||||
|
||||
_logger?.Shutdown();
|
||||
_logger.Shutdown();
|
||||
|
||||
var timeoutToken = new CancellationTokenSource(Options.ShutdownTimeout).Token;
|
||||
if (!cancellationToken.CanBeCanceled)
|
||||
|
|
@ -364,7 +365,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.ServerShutdownException(ex);
|
||||
_logger.ServerShutdownException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@
|
|||
<Reference Include="System.ServiceProcess.ServiceController" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="WebHostService.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Update="WebHostService.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
|
|||
|
||||
if (!initMatchRes.Success)
|
||||
{
|
||||
context.Logger?.ModRewriteNotMatchedRule();
|
||||
context.Logger.ModRewriteNotMatchedRule();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
|
|||
var condResult = ConditionEvaluator.Evaluate(Conditions, context, initMatchRes.BackReferences);
|
||||
if (!condResult.Success)
|
||||
{
|
||||
context.Logger?.ModRewriteNotMatchedRule();
|
||||
context.Logger.ModRewriteNotMatchedRule();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
|
|||
|
||||
// At this point, we know our rule passed, first apply pre conditions,
|
||||
// which can modify things like the cookie or env, and then apply the action
|
||||
context.Logger?.ModRewriteMatchedRule();
|
||||
context.Logger.ModRewriteMatchedRule();
|
||||
|
||||
foreach (var action in Actions)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
|
|||
|
||||
if (!initMatchResults.Success)
|
||||
{
|
||||
context.Logger?.UrlRewriteNotMatchedRule(Name);
|
||||
context.Logger.UrlRewriteNotMatchedRule(Name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -62,14 +62,14 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
|
|||
condResult = ConditionEvaluator.Evaluate(Conditions, context, initMatchResults.BackReferences);
|
||||
if (!condResult.Success)
|
||||
{
|
||||
context.Logger?.UrlRewriteNotMatchedRule(Name);
|
||||
context.Logger.UrlRewriteNotMatchedRule(Name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
context.Logger?.UrlRewriteMatchedRule(Name);
|
||||
context.Logger.UrlRewriteMatchedRule(Name);
|
||||
// at this point we know the rule passed, evaluate the replacement.
|
||||
Action.ApplyAction(context, initMatchResults?.BackReferences, condResult?.BackReferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal
|
|||
response.Headers[HeaderNames.Location] = pathBase + newPath + context.HttpContext.Request.QueryString.ToUriComponent();
|
||||
}
|
||||
|
||||
context.Logger?.RedirectedRequest(newPath);
|
||||
context.Logger.RedirectedRequest(newPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Text;
|
||||
|
|
@ -35,8 +35,8 @@ namespace Microsoft.AspNetCore.Rewrite.Internal
|
|||
response.StatusCode = StatusCode;
|
||||
response.Headers[HeaderNames.Location] = newUrl.ToString();
|
||||
context.Result = RuleResult.EndResponse;
|
||||
context.Logger?.RedirectedToHttps();
|
||||
context.Logger.RedirectedToHttps();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal
|
|||
response.StatusCode = _statusCode;
|
||||
response.Headers[HeaderNames.Location] = newUrl;
|
||||
context.Result = RuleResult.EndResponse;
|
||||
context.Logger?.RedirectedToWww();
|
||||
context.Logger.RedirectedToWww();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal
|
|||
}
|
||||
}
|
||||
|
||||
context.Logger?.RewrittenRequest(result);
|
||||
context.Logger.RewrittenRequest(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNetCore.Rewrite.Logging;
|
||||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
|
|||
{
|
||||
context.HttpContext.Abort();
|
||||
context.Result = RuleResult.EndResponse;
|
||||
context.Logger?.AbortedRequest(context.HttpContext.Request.Path + context.HttpContext.Request.QueryString);
|
||||
context.Logger.AbortedRequest(context.HttpContext.Request.Path + context.HttpContext.Request.QueryString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
|
|||
|
||||
context.Result = RuleResult.EndResponse;
|
||||
|
||||
context.Logger?.CustomResponse(context.HttpContext.Request.GetEncodedUrl());
|
||||
context.Logger.CustomResponse(context.HttpContext.Request.GetEncodedUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNetCore.Rewrite
|
||||
{
|
||||
|
|
@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Rewrite
|
|||
/// <summary>
|
||||
/// Gets and sets the logger
|
||||
/// </summary>
|
||||
public ILogger Logger { get; set; }
|
||||
public ILogger Logger { get; set; } = NullLogger.Instance;
|
||||
|
||||
/// <summary>
|
||||
/// A shared result that is set appropriately by each rule for the next action that
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
|
||||
{
|
||||
|
|
@ -68,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
|
|||
}
|
||||
|
||||
_options = options;
|
||||
_logger = loggerFactory?.CreateLogger<HttpsConnectionAdapter>();
|
||||
_logger = loggerFactory?.CreateLogger<HttpsConnectionAdapter>() ?? (ILogger)NullLogger.Instance;
|
||||
}
|
||||
|
||||
public bool IsHttps => true;
|
||||
|
|
@ -181,13 +182,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
|
|||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_logger?.LogDebug(2, CoreStrings.AuthenticationTimedOut);
|
||||
_logger.LogDebug(2, CoreStrings.AuthenticationTimedOut);
|
||||
sslStream.Dispose();
|
||||
return _closedAdaptedConnection;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is AuthenticationException)
|
||||
{
|
||||
_logger?.LogDebug(1, ex, CoreStrings.AuthenticationFailed);
|
||||
_logger.LogDebug(1, ex, CoreStrings.AuthenticationFailed);
|
||||
sslStream.Dispose();
|
||||
return _closedAdaptedConnection;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue