replacing string interpolation with proper logging syntax (#363)
This commit is contained in:
parent
f171aa4a64
commit
4a4dde182f
|
|
@ -102,7 +102,11 @@ namespace Microsoft.AspNetCore.HostFiltering
|
||||||
throw new InvalidOperationException("No allowed hosts were configured.");
|
throw new InvalidOperationException("No allowed hosts were configured.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogDebug("Allowed hosts: " + string.Join("; ", allowedHosts));
|
if (_logger.IsEnabled(LogLevel.Debug))
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Allowed hosts: {Hosts}", string.Join("; ", allowedHosts));
|
||||||
|
}
|
||||||
|
|
||||||
_allowedHosts = allowedHosts;
|
_allowedHosts = allowedHosts;
|
||||||
return _allowedHosts;
|
return _allowedHosts;
|
||||||
}
|
}
|
||||||
|
|
@ -148,29 +152,26 @@ namespace Microsoft.AspNetCore.HostFiltering
|
||||||
// Http/1.1 requires the header but the value may be empty.
|
// Http/1.1 requires the header but the value may be empty.
|
||||||
if (!_options.AllowEmptyHosts)
|
if (!_options.AllowEmptyHosts)
|
||||||
{
|
{
|
||||||
_logger.LogInformation($"{context.Request.Protocol} request rejected due to missing or empty host header.");
|
_logger.LogInformation("{Protocol} request rejected due to missing or empty host header.", context.Request.Protocol);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (_logger.IsEnabled(LogLevel.Debug))
|
_logger.LogDebug("{Protocol} request allowed with missing or empty host header.", context.Request.Protocol);
|
||||||
{
|
|
||||||
_logger.LogDebug($"{context.Request.Protocol} request allowed with missing or empty host header.");
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_allowAnyNonEmptyHost == true)
|
if (_allowAnyNonEmptyHost == true)
|
||||||
{
|
{
|
||||||
_logger.LogTrace($"All hosts are allowed.");
|
_logger.LogTrace("All hosts are allowed.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HostString.MatchesAny(host, allowedHosts))
|
if (HostString.MatchesAny(host, allowedHosts))
|
||||||
{
|
{
|
||||||
_logger.LogTrace($"The host '{host}' matches an allowed host.");
|
_logger.LogTrace("The host '{Host}' matches an allowed host.", host);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation($"The host '{host}' does not match an allowed host.");
|
_logger.LogInformation("The host '{Host}' does not match an allowed host.", host);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.HttpOverrides
|
||||||
if (currentValues.RemoteIpAndPort != null && checkKnownIps && !CheckKnownAddress(currentValues.RemoteIpAndPort.Address))
|
if (currentValues.RemoteIpAndPort != null && checkKnownIps && !CheckKnownAddress(currentValues.RemoteIpAndPort.Address))
|
||||||
{
|
{
|
||||||
// Stop at the first unknown remote IP, but still apply changes processed so far.
|
// Stop at the first unknown remote IP, but still apply changes processed so far.
|
||||||
_logger.LogDebug(1, $"Unknown proxy: {currentValues.RemoteIpAndPort}");
|
_logger.LogDebug(1, "Unknown proxy: {RemoteIpAndPort}", currentValues.RemoteIpAndPort);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,12 +248,12 @@ namespace Microsoft.AspNetCore.HttpOverrides
|
||||||
else if (!string.IsNullOrEmpty(set.IpAndPortText))
|
else if (!string.IsNullOrEmpty(set.IpAndPortText))
|
||||||
{
|
{
|
||||||
// Stop at the first unparsable IP, but still apply changes processed so far.
|
// Stop at the first unparsable IP, but still apply changes processed so far.
|
||||||
_logger.LogDebug(1, $"Unparsable IP: {set.IpAndPortText}");
|
_logger.LogDebug(1, "Unparsable IP: {IpAndPortText}", set.IpAndPortText);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (_options.RequireHeaderSymmetry)
|
else if (_options.RequireHeaderSymmetry)
|
||||||
{
|
{
|
||||||
_logger.LogWarning(2, $"Missing forwarded IPAddress.");
|
_logger.LogWarning(2, "Missing forwarded IPAddress.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue