From 3c9cb4f3b573ff620b4f4498757ee112a9934c7f Mon Sep 17 00:00:00 2001 From: Kahbazi Date: Wed, 9 Jan 2019 07:56:58 +0330 Subject: [PATCH] Add event name in Middlewares (#6467) --- .../CORS/src/Internal/CORSLoggerExtensions.cs | 24 +- .../src/internal/HstsLoggingExtensions.cs | 17 +- .../src/internal/HttpsLoggingExtensions.cs | 30 +- .../RequestCultureProviderLoggerExtensions.cs | 6 +- .../src/Internal/LoggerExtensions.cs | 290 +++++++++--------- .../Internal/ResponseCachingPolicyProvider.cs | 44 +-- .../src/ResponseCachingMiddleware.cs | 20 +- .../ResponseCompressionLoggingExtensions.cs | 47 ++- .../RewriteMiddlewareLoggingExtensions.cs | 60 ++-- .../ApacheModRewrite/ApacheModRewriteRule.cs | 4 +- .../IISUrlRewrite/IISUrlRewriteRule.cs | 4 +- .../Rewrite/src/Internal/RedirectRule.cs | 4 +- .../Rewrite/src/Internal/RewriteRule.cs | 2 +- .../Session/src/LoggingExtensions.cs | 26 +- 14 files changed, 319 insertions(+), 259 deletions(-) diff --git a/src/Middleware/CORS/src/Internal/CORSLoggerExtensions.cs b/src/Middleware/CORS/src/Internal/CORSLoggerExtensions.cs index ee6533bbed..815bbfc2a2 100644 --- a/src/Middleware/CORS/src/Internal/CORSLoggerExtensions.cs +++ b/src/Middleware/CORS/src/Internal/CORSLoggerExtensions.cs @@ -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; @@ -25,47 +25,47 @@ namespace Microsoft.AspNetCore.Cors.Internal { _isPreflightRequest = LoggerMessage.Define( LogLevel.Debug, - 1, + new EventId(1, "IsPreflightRequest"), "The request is a preflight request."); _requestHasOriginHeader = LoggerMessage.Define( LogLevel.Debug, - 2, + new EventId(2, "RequestHasOriginHeader"), "The request has an origin header: '{origin}'."); _requestDoesNotHaveOriginHeader = LoggerMessage.Define( LogLevel.Debug, - 3, + new EventId(3, "RequestDoesNotHaveOriginHeader"), "The request does not have an origin header."); _policySuccess = LoggerMessage.Define( LogLevel.Information, - 4, + new EventId(4, "PolicySuccess"), "CORS policy execution successful."); _policyFailure = LoggerMessage.Define( LogLevel.Information, - 5, + new EventId(5, "PolicyFailure"), "CORS policy execution failed."); _originNotAllowed = LoggerMessage.Define( LogLevel.Information, - 6, + new EventId(6, "OriginNotAllowed"), "Request origin {origin} does not have permission to access the resource."); _accessControlMethodNotAllowed = LoggerMessage.Define( LogLevel.Information, - 7, + new EventId(7, "AccessControlMethodNotAllowed"), "Request method {accessControlRequestMethod} not allowed in CORS policy."); _requestHeaderNotAllowed = LoggerMessage.Define( LogLevel.Information, - 8, + new EventId(8, "RequestHeaderNotAllowed"), "Request header '{requestHeader}' not allowed in CORS policy."); _failedToSetCorsHeaders = LoggerMessage.Define( LogLevel.Warning, - 9, + new EventId(9, "FailedToSetCorsHeaders"), "Failed to apply CORS Response headers."); _noCorsPolicyFound = LoggerMessage.Define( @@ -75,12 +75,12 @@ namespace Microsoft.AspNetCore.Cors.Internal _insecureConfiguration = LoggerMessage.Define( LogLevel.Warning, - new EventId(11, "CorsInsecureConfiguration"), + new EventId(11, "InsecureConfiguration"), "The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the policy by listing individual origins if credentials needs to be supported."); _isNotPreflightRequest = LoggerMessage.Define( LogLevel.Debug, - new EventId(12, "OptionsRequestWithoutAccessControlRequestMethodHeader"), + new EventId(12, "IsNotPreflightRequest"), "This request uses the HTTP OPTIONS method but does not have an Access-Control-Request-Method header. This request will not be treated as a CORS preflight request."); } diff --git a/src/Middleware/HttpsPolicy/src/internal/HstsLoggingExtensions.cs b/src/Middleware/HttpsPolicy/src/internal/HstsLoggingExtensions.cs index 5162ccb9f5..b9e495db56 100644 --- a/src/Middleware/HttpsPolicy/src/internal/HstsLoggingExtensions.cs +++ b/src/Middleware/HttpsPolicy/src/internal/HstsLoggingExtensions.cs @@ -14,9 +14,20 @@ namespace Microsoft.AspNetCore.HttpsPolicy.Internal static HstsLoggingExtensions() { - _notSecure = LoggerMessage.Define(LogLevel.Debug, 1, "The request is insecure. Skipping HSTS header."); - _excludedHost = LoggerMessage.Define(LogLevel.Debug, 2, "The host '{host}' is excluded. Skipping HSTS header."); - _addingHstsHeader = LoggerMessage.Define(LogLevel.Trace, 3, "Adding HSTS header to response."); + _notSecure = LoggerMessage.Define( + LogLevel.Debug, + new EventId(1, "NotSecure"), + "The request is insecure. Skipping HSTS header."); + + _excludedHost = LoggerMessage.Define( + LogLevel.Debug, + new EventId(2, "ExcludedHost"), + "The host '{host}' is excluded. Skipping HSTS header."); + + _addingHstsHeader = LoggerMessage.Define( + LogLevel.Trace, + new EventId(3, "AddingHstsHeader"), + "Adding HSTS header to response."); } public static void SkippingInsecure(this ILogger logger) diff --git a/src/Middleware/HttpsPolicy/src/internal/HttpsLoggingExtensions.cs b/src/Middleware/HttpsPolicy/src/internal/HttpsLoggingExtensions.cs index 55e65dcbdd..4bbf6b1904 100644 --- a/src/Middleware/HttpsPolicy/src/internal/HttpsLoggingExtensions.cs +++ b/src/Middleware/HttpsPolicy/src/internal/HttpsLoggingExtensions.cs @@ -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; @@ -16,13 +16,31 @@ namespace Microsoft.AspNetCore.HttpsPolicy.Internal static HttpsLoggingExtensions() { - _redirectingToHttps = LoggerMessage.Define(LogLevel.Debug, 1, "Redirecting to '{redirect}'."); - _portLoadedFromConfig = LoggerMessage.Define(LogLevel.Debug, 2, "Https port '{port}' loaded from configuration."); - _failedToDeterminePort = LoggerMessage.Define(LogLevel.Warning, 3, "Failed to determine the https port for redirect."); - _failedMultiplePorts = LoggerMessage.Define(LogLevel.Warning, 4, + _redirectingToHttps = LoggerMessage.Define( + LogLevel.Debug, + new EventId(1, "RedirectingToHttps"), + "Redirecting to '{redirect}'."); + + _portLoadedFromConfig = LoggerMessage.Define( + LogLevel.Debug, + new EventId(2, "PortLoadedFromConfig"), + "Https port '{port}' loaded from configuration."); + + _failedToDeterminePort = LoggerMessage.Define( + LogLevel.Warning, + new EventId(3, "FailedToDeterminePort"), + "Failed to determine the https port for redirect."); + + _failedMultiplePorts = LoggerMessage.Define( + LogLevel.Warning, + new EventId(4, "FailedMultiplePorts"), "Cannot determine the https port from IServerAddressesFeature, multiple values were found. " + "Please set the desired port explicitly on HttpsRedirectionOptions.HttpsPort."); - _portFromServer = LoggerMessage.Define(LogLevel.Debug, 5, "Https port '{httpsPort}' discovered from server endpoints."); + + _portFromServer = LoggerMessage.Define( + LogLevel.Debug, + new EventId(5, "PortFromServer"), + "Https port '{httpsPort}' discovered from server endpoints."); } public static void RedirectingToHttps(this ILogger logger, string redirect) diff --git a/src/Middleware/Localization/src/Internal/RequestCultureProviderLoggerExtensions.cs b/src/Middleware/Localization/src/Internal/RequestCultureProviderLoggerExtensions.cs index ee435cda69..c8583ce486 100644 --- a/src/Middleware/Localization/src/Internal/RequestCultureProviderLoggerExtensions.cs +++ b/src/Middleware/Localization/src/Internal/RequestCultureProviderLoggerExtensions.cs @@ -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; @@ -17,11 +17,11 @@ namespace Microsoft.AspNetCore.Localization.Internal { _unsupportedCulture = LoggerMessage.Define>( LogLevel.Warning, - 1, + new EventId (1, "UnsupportedCulture"), "{requestCultureProvider} returned the following unsupported cultures '{cultures}'."); _unsupportedUICulture = LoggerMessage.Define>( LogLevel.Warning, - 2, + new EventId(2, "UnsupportedUICulture"), "{requestCultureProvider} returned the following unsupported UI Cultures '{uiCultures}'."); } diff --git a/src/Middleware/ResponseCaching/src/Internal/LoggerExtensions.cs b/src/Middleware/ResponseCaching/src/Internal/LoggerExtensions.cs index 5039925e93..c77dc3bfa3 100644 --- a/src/Middleware/ResponseCaching/src/Internal/LoggerExtensions.cs +++ b/src/Middleware/ResponseCaching/src/Internal/LoggerExtensions.cs @@ -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; @@ -12,299 +12,299 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal /// internal static class LoggerExtensions { - private static readonly Action _logRequestMethodNotCacheable; - private static readonly Action _logRequestWithAuthorizationNotCacheable; - private static readonly Action _logRequestWithNoCacheNotCacheable; - private static readonly Action _logRequestWithPragmaNoCacheNotCacheable; - private static readonly Action _logExpirationMinFreshAdded; - private static readonly Action _logExpirationSharedMaxAgeExceeded; - private static readonly Action _logExpirationMustRevalidate; - private static readonly Action _logExpirationMaxStaleSatisfied; - private static readonly Action _logExpirationMaxAgeExceeded; - private static readonly Action _logExpirationExpiresExceeded; - private static readonly Action _logResponseWithoutPublicNotCacheable; - private static readonly Action _logResponseWithNoStoreNotCacheable; - private static readonly Action _logResponseWithNoCacheNotCacheable; - private static readonly Action _logResponseWithSetCookieNotCacheable; - private static readonly Action _logResponseWithVaryStarNotCacheable; - private static readonly Action _logResponseWithPrivateNotCacheable; - private static readonly Action _logResponseWithUnsuccessfulStatusCodeNotCacheable; - private static readonly Action _logNotModifiedIfNoneMatchStar; - private static readonly Action _logNotModifiedIfNoneMatchMatched; - private static readonly Action _logNotModifiedIfModifiedSinceSatisfied; - private static readonly Action _logNotModifiedServed; - private static readonly Action _logCachedResponseServed; - private static readonly Action _logGatewayTimeoutServed; - private static readonly Action _logNoResponseServed; - private static readonly Action _logVaryByRulesUpdated; - private static readonly Action _logResponseCached; - private static readonly Action _logResponseNotCached; - private static readonly Action _logResponseContentLengthMismatchNotCached; - private static readonly Action _logExpirationInfiniteMaxStaleSatisfied; + private static readonly Action _requestMethodNotCacheable; + private static readonly Action _requestWithAuthorizationNotCacheable; + private static readonly Action _requestWithNoCacheNotCacheable; + private static readonly Action _requestWithPragmaNoCacheNotCacheable; + private static readonly Action _expirationMinFreshAdded; + private static readonly Action _expirationSharedMaxAgeExceeded; + private static readonly Action _expirationMustRevalidate; + private static readonly Action _expirationMaxStaleSatisfied; + private static readonly Action _expirationMaxAgeExceeded; + private static readonly Action _expirationExpiresExceeded; + private static readonly Action _responseWithoutPublicNotCacheable; + private static readonly Action _responseWithNoStoreNotCacheable; + private static readonly Action _responseWithNoCacheNotCacheable; + private static readonly Action _responseWithSetCookieNotCacheable; + private static readonly Action _responseWithVaryStarNotCacheable; + private static readonly Action _responseWithPrivateNotCacheable; + private static readonly Action _responseWithUnsuccessfulStatusCodeNotCacheable; + private static readonly Action _notModifiedIfNoneMatchStar; + private static readonly Action _notModifiedIfNoneMatchMatched; + private static readonly Action _notModifiedIfModifiedSinceSatisfied; + private static readonly Action _notModifiedServed; + private static readonly Action _cachedResponseServed; + private static readonly Action _gatewayTimeoutServed; + private static readonly Action _noResponseServed; + private static readonly Action _varyByRulesUpdated; + private static readonly Action _responseCached; + private static readonly Action _responseNotCached; + private static readonly Action _responseContentLengthMismatchNotCached; + private static readonly Action _expirationInfiniteMaxStaleSatisfied; static LoggerExtensions() { - _logRequestMethodNotCacheable = LoggerMessage.Define( + _requestMethodNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 1, + eventId: new EventId(1, "RequestMethodNotCacheable"), formatString: "The request cannot be served from cache because it uses the HTTP method: {Method}."); - _logRequestWithAuthorizationNotCacheable = LoggerMessage.Define( + _requestWithAuthorizationNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 2, + eventId: new EventId(2, "RequestWithAuthorizationNotCacheable"), formatString: $"The request cannot be served from cache because it contains an '{HeaderNames.Authorization}' header."); - _logRequestWithNoCacheNotCacheable = LoggerMessage.Define( + _requestWithNoCacheNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 3, + eventId: new EventId(3, "RequestWithNoCacheNotCacheable"), formatString: "The request cannot be served from cache because it contains a 'no-cache' cache directive."); - _logRequestWithPragmaNoCacheNotCacheable = LoggerMessage.Define( + _requestWithPragmaNoCacheNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 4, + eventId: new EventId(4, "RequestWithPragmaNoCacheNotCacheable"), formatString: "The request cannot be served from cache because it contains a 'no-cache' pragma directive."); - _logExpirationMinFreshAdded = LoggerMessage.Define( + _expirationMinFreshAdded = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 5, + eventId: new EventId(5, "LogRequestMethodNotCacheable"), formatString: "Adding a minimum freshness requirement of {Duration} specified by the 'min-fresh' cache directive."); - _logExpirationSharedMaxAgeExceeded = LoggerMessage.Define( + _expirationSharedMaxAgeExceeded = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 6, + eventId: new EventId(6, "ExpirationSharedMaxAgeExceeded"), formatString: "The age of the entry is {Age} and has exceeded the maximum age for shared caches of {SharedMaxAge} specified by the 's-maxage' cache directive."); - _logExpirationMustRevalidate = LoggerMessage.Define( + _expirationMustRevalidate = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 7, + eventId: new EventId(7, "ExpirationMustRevalidate"), formatString: "The age of the entry is {Age} and has exceeded the maximum age of {MaxAge} specified by the 'max-age' cache directive. It must be revalidated because the 'must-revalidate' or 'proxy-revalidate' cache directive is specified."); - _logExpirationMaxStaleSatisfied = LoggerMessage.Define( + _expirationMaxStaleSatisfied = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 8, + eventId: new EventId(8, "ExpirationMaxStaleSatisfied"), formatString: "The age of the entry is {Age} and has exceeded the maximum age of {MaxAge} specified by the 'max-age' cache directive. However, it satisfied the maximum stale allowance of {MaxStale} specified by the 'max-stale' cache directive."); - _logExpirationMaxAgeExceeded = LoggerMessage.Define( + _expirationMaxAgeExceeded = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 9, + eventId: new EventId(9, "ExpirationMaxAgeExceeded"), formatString: "The age of the entry is {Age} and has exceeded the maximum age of {MaxAge} specified by the 'max-age' cache directive."); - _logExpirationExpiresExceeded = LoggerMessage.Define( + _expirationExpiresExceeded = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 10, + eventId: new EventId(10, "ExpirationExpiresExceeded"), formatString: $"The response time of the entry is {{ResponseTime}} and has exceeded the expiry date of {{Expired}} specified by the '{HeaderNames.Expires}' header."); - _logResponseWithoutPublicNotCacheable = LoggerMessage.Define( + _responseWithoutPublicNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 11, + eventId: new EventId(11, "ResponseWithoutPublicNotCacheable"), formatString: "Response is not cacheable because it does not contain the 'public' cache directive."); - _logResponseWithNoStoreNotCacheable = LoggerMessage.Define( + _responseWithNoStoreNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 12, + eventId: new EventId(12, "ResponseWithNoStoreNotCacheable"), formatString: "Response is not cacheable because it or its corresponding request contains a 'no-store' cache directive."); - _logResponseWithNoCacheNotCacheable = LoggerMessage.Define( + _responseWithNoCacheNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 13, + eventId: new EventId(13, "ResponseWithNoCacheNotCacheable"), formatString: "Response is not cacheable because it contains a 'no-cache' cache directive."); - _logResponseWithSetCookieNotCacheable = LoggerMessage.Define( + _responseWithSetCookieNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 14, + eventId: new EventId(14, "ResponseWithSetCookieNotCacheable"), formatString: $"Response is not cacheable because it contains a '{HeaderNames.SetCookie}' header."); - _logResponseWithVaryStarNotCacheable = LoggerMessage.Define( + _responseWithVaryStarNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 15, + eventId: new EventId(15, "ResponseWithVaryStarNotCacheable"), formatString: $"Response is not cacheable because it contains a '{HeaderNames.Vary}' header with a value of *."); - _logResponseWithPrivateNotCacheable = LoggerMessage.Define( + _responseWithPrivateNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 16, + eventId: new EventId(16, "ResponseWithPrivateNotCacheable"), formatString: "Response is not cacheable because it contains the 'private' cache directive."); - _logResponseWithUnsuccessfulStatusCodeNotCacheable = LoggerMessage.Define( + _responseWithUnsuccessfulStatusCodeNotCacheable = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 17, + eventId: new EventId(17, "ResponseWithUnsuccessfulStatusCodeNotCacheable"), formatString: "Response is not cacheable because its status code {StatusCode} does not indicate success."); - _logNotModifiedIfNoneMatchStar = LoggerMessage.Define( + _notModifiedIfNoneMatchStar = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 18, + eventId: new EventId(18, "ExpirationExpiresExceeded"), formatString: $"The '{HeaderNames.IfNoneMatch}' header of the request contains a value of *."); - _logNotModifiedIfNoneMatchMatched = LoggerMessage.Define( + _notModifiedIfNoneMatchMatched = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 19, + eventId: new EventId(19, "NotModifiedIfNoneMatchMatched"), formatString: $"The ETag {{ETag}} in the '{HeaderNames.IfNoneMatch}' header matched the ETag of a cached entry."); - _logNotModifiedIfModifiedSinceSatisfied = LoggerMessage.Define( + _notModifiedIfModifiedSinceSatisfied = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 20, + eventId: new EventId(20, "NotModifiedIfModifiedSinceSatisfied"), formatString: $"The last modified date of {{LastModified}} is before the date {{IfModifiedSince}} specified in the '{HeaderNames.IfModifiedSince}' header."); - _logNotModifiedServed = LoggerMessage.Define( + _notModifiedServed = LoggerMessage.Define( logLevel: LogLevel.Information, - eventId: 21, + eventId: new EventId(21, "NotModifiedServed"), formatString: "The content requested has not been modified."); - _logCachedResponseServed = LoggerMessage.Define( + _cachedResponseServed = LoggerMessage.Define( logLevel: LogLevel.Information, - eventId: 22, + eventId: new EventId(22, "CachedResponseServed"), formatString: "Serving response from cache."); - _logGatewayTimeoutServed = LoggerMessage.Define( + _gatewayTimeoutServed = LoggerMessage.Define( logLevel: LogLevel.Information, - eventId: 23, + eventId: new EventId(23, "GatewayTimeoutServed"), formatString: "No cached response available for this request and the 'only-if-cached' cache directive was specified."); - _logNoResponseServed = LoggerMessage.Define( + _noResponseServed = LoggerMessage.Define( logLevel: LogLevel.Information, - eventId: 24, + eventId: new EventId(24, "NoResponseServed"), formatString: "No cached response available for this request."); - _logVaryByRulesUpdated = LoggerMessage.Define( + _varyByRulesUpdated = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 25, + eventId: new EventId(25, "VaryByRulesUpdated"), formatString: "Vary by rules were updated. Headers: {Headers}, Query keys: {QueryKeys}"); - _logResponseCached = LoggerMessage.Define( + _responseCached = LoggerMessage.Define( logLevel: LogLevel.Information, - eventId: 26, + eventId: new EventId(26, "ResponseCached"), formatString: "The response has been cached."); - _logResponseNotCached = LoggerMessage.Define( + _responseNotCached = LoggerMessage.Define( logLevel: LogLevel.Information, - eventId: 27, + eventId: new EventId(27, "ResponseNotCached"), formatString: "The response could not be cached for this request."); - _logResponseContentLengthMismatchNotCached = LoggerMessage.Define( + _responseContentLengthMismatchNotCached = LoggerMessage.Define( logLevel: LogLevel.Warning, - eventId: 28, + eventId: new EventId(28, "responseContentLengthMismatchNotCached"), formatString: $"The response could not be cached for this request because the '{HeaderNames.ContentLength}' did not match the body length."); - _logExpirationInfiniteMaxStaleSatisfied = LoggerMessage.Define( + _expirationInfiniteMaxStaleSatisfied = LoggerMessage.Define( logLevel: LogLevel.Debug, - eventId: 29, + eventId: new EventId(29, "ExpirationInfiniteMaxStaleSatisfied"), formatString: "The age of the entry is {Age} and has exceeded the maximum age of {MaxAge} specified by the 'max-age' cache directive. However, the 'max-stale' cache directive was specified without an assigned value and a stale response of any age is accepted."); } - internal static void LogRequestMethodNotCacheable(this ILogger logger, string method) + internal static void RequestMethodNotCacheable(this ILogger logger, string method) { - _logRequestMethodNotCacheable(logger, method, null); + _requestMethodNotCacheable(logger, method, null); } - internal static void LogRequestWithAuthorizationNotCacheable(this ILogger logger) + internal static void RequestWithAuthorizationNotCacheable(this ILogger logger) { - _logRequestWithAuthorizationNotCacheable(logger, null); + _requestWithAuthorizationNotCacheable(logger, null); } - internal static void LogRequestWithNoCacheNotCacheable(this ILogger logger) + internal static void RequestWithNoCacheNotCacheable(this ILogger logger) { - _logRequestWithNoCacheNotCacheable(logger, null); + _requestWithNoCacheNotCacheable(logger, null); } - internal static void LogRequestWithPragmaNoCacheNotCacheable(this ILogger logger) + internal static void RequestWithPragmaNoCacheNotCacheable(this ILogger logger) { - _logRequestWithPragmaNoCacheNotCacheable(logger, null); + _requestWithPragmaNoCacheNotCacheable(logger, null); } - internal static void LogExpirationMinFreshAdded(this ILogger logger, TimeSpan duration) + internal static void ExpirationMinFreshAdded(this ILogger logger, TimeSpan duration) { - _logExpirationMinFreshAdded(logger, duration, null); + _expirationMinFreshAdded(logger, duration, null); } - internal static void LogExpirationSharedMaxAgeExceeded(this ILogger logger, TimeSpan age, TimeSpan sharedMaxAge) + internal static void ExpirationSharedMaxAgeExceeded(this ILogger logger, TimeSpan age, TimeSpan sharedMaxAge) { - _logExpirationSharedMaxAgeExceeded(logger, age, sharedMaxAge, null); + _expirationSharedMaxAgeExceeded(logger, age, sharedMaxAge, null); } - internal static void LogExpirationMustRevalidate(this ILogger logger, TimeSpan age, TimeSpan maxAge) + internal static void ExpirationMustRevalidate(this ILogger logger, TimeSpan age, TimeSpan maxAge) { - _logExpirationMustRevalidate(logger, age, maxAge, null); + _expirationMustRevalidate(logger, age, maxAge, null); } - internal static void LogExpirationMaxStaleSatisfied(this ILogger logger, TimeSpan age, TimeSpan maxAge, TimeSpan maxStale) + internal static void ExpirationMaxStaleSatisfied(this ILogger logger, TimeSpan age, TimeSpan maxAge, TimeSpan maxStale) { - _logExpirationMaxStaleSatisfied(logger, age, maxAge, maxStale, null); + _expirationMaxStaleSatisfied(logger, age, maxAge, maxStale, null); } - internal static void LogExpirationMaxAgeExceeded(this ILogger logger, TimeSpan age, TimeSpan sharedMaxAge) + internal static void ExpirationMaxAgeExceeded(this ILogger logger, TimeSpan age, TimeSpan sharedMaxAge) { - _logExpirationMaxAgeExceeded(logger, age, sharedMaxAge, null); + _expirationMaxAgeExceeded(logger, age, sharedMaxAge, null); } - internal static void LogExpirationExpiresExceeded(this ILogger logger, DateTimeOffset responseTime, DateTimeOffset expires) + internal static void ExpirationExpiresExceeded(this ILogger logger, DateTimeOffset responseTime, DateTimeOffset expires) { - _logExpirationExpiresExceeded(logger, responseTime, expires, null); + _expirationExpiresExceeded(logger, responseTime, expires, null); } - internal static void LogResponseWithoutPublicNotCacheable(this ILogger logger) + internal static void ResponseWithoutPublicNotCacheable(this ILogger logger) { - _logResponseWithoutPublicNotCacheable(logger, null); + _responseWithoutPublicNotCacheable(logger, null); } - internal static void LogResponseWithNoStoreNotCacheable(this ILogger logger) + internal static void ResponseWithNoStoreNotCacheable(this ILogger logger) { - _logResponseWithNoStoreNotCacheable(logger, null); + _responseWithNoStoreNotCacheable(logger, null); } - internal static void LogResponseWithNoCacheNotCacheable(this ILogger logger) + internal static void ResponseWithNoCacheNotCacheable(this ILogger logger) { - _logResponseWithNoCacheNotCacheable(logger, null); + _responseWithNoCacheNotCacheable(logger, null); } - internal static void LogResponseWithSetCookieNotCacheable(this ILogger logger) + internal static void ResponseWithSetCookieNotCacheable(this ILogger logger) { - _logResponseWithSetCookieNotCacheable(logger, null); + _responseWithSetCookieNotCacheable(logger, null); } - internal static void LogResponseWithVaryStarNotCacheable(this ILogger logger) + internal static void ResponseWithVaryStarNotCacheable(this ILogger logger) { - _logResponseWithVaryStarNotCacheable(logger, null); + _responseWithVaryStarNotCacheable(logger, null); } - internal static void LogResponseWithPrivateNotCacheable(this ILogger logger) + internal static void ResponseWithPrivateNotCacheable(this ILogger logger) { - _logResponseWithPrivateNotCacheable(logger, null); + _responseWithPrivateNotCacheable(logger, null); } - internal static void LogResponseWithUnsuccessfulStatusCodeNotCacheable(this ILogger logger, int statusCode) + internal static void ResponseWithUnsuccessfulStatusCodeNotCacheable(this ILogger logger, int statusCode) { - _logResponseWithUnsuccessfulStatusCodeNotCacheable(logger, statusCode, null); + _responseWithUnsuccessfulStatusCodeNotCacheable(logger, statusCode, null); } - internal static void LogNotModifiedIfNoneMatchStar(this ILogger logger) + internal static void NotModifiedIfNoneMatchStar(this ILogger logger) { - _logNotModifiedIfNoneMatchStar(logger, null); + _notModifiedIfNoneMatchStar(logger, null); } - internal static void LogNotModifiedIfNoneMatchMatched(this ILogger logger, EntityTagHeaderValue etag) + internal static void NotModifiedIfNoneMatchMatched(this ILogger logger, EntityTagHeaderValue etag) { - _logNotModifiedIfNoneMatchMatched(logger, etag, null); + _notModifiedIfNoneMatchMatched(logger, etag, null); } - internal static void LogNotModifiedIfModifiedSinceSatisfied(this ILogger logger, DateTimeOffset lastModified, DateTimeOffset ifModifiedSince) + internal static void NotModifiedIfModifiedSinceSatisfied(this ILogger logger, DateTimeOffset lastModified, DateTimeOffset ifModifiedSince) { - _logNotModifiedIfModifiedSinceSatisfied(logger, lastModified, ifModifiedSince, null); + _notModifiedIfModifiedSinceSatisfied(logger, lastModified, ifModifiedSince, null); } - internal static void LogNotModifiedServed(this ILogger logger) + internal static void NotModifiedServed(this ILogger logger) { - _logNotModifiedServed(logger, null); + _notModifiedServed(logger, null); } - internal static void LogCachedResponseServed(this ILogger logger) + internal static void CachedResponseServed(this ILogger logger) { - _logCachedResponseServed(logger, null); + _cachedResponseServed(logger, null); } - internal static void LogGatewayTimeoutServed(this ILogger logger) + internal static void GatewayTimeoutServed(this ILogger logger) { - _logGatewayTimeoutServed(logger, null); + _gatewayTimeoutServed(logger, null); } - internal static void LogNoResponseServed(this ILogger logger) + internal static void NoResponseServed(this ILogger logger) { - _logNoResponseServed(logger, null); + _noResponseServed(logger, null); } - internal static void LogVaryByRulesUpdated(this ILogger logger, string headers, string queryKeys) + internal static void VaryByRulesUpdated(this ILogger logger, string headers, string queryKeys) { - _logVaryByRulesUpdated(logger, headers, queryKeys, null); + _varyByRulesUpdated(logger, headers, queryKeys, null); } - internal static void LogResponseCached(this ILogger logger) + internal static void ResponseCached(this ILogger logger) { - _logResponseCached(logger, null); + _responseCached(logger, null); } internal static void LogResponseNotCached(this ILogger logger) { - _logResponseNotCached(logger, null); + _responseNotCached(logger, null); } - internal static void LogResponseContentLengthMismatchNotCached(this ILogger logger) + internal static void ResponseContentLengthMismatchNotCached(this ILogger logger) { - _logResponseContentLengthMismatchNotCached(logger, null); + _responseContentLengthMismatchNotCached(logger, null); } - internal static void LogExpirationInfiniteMaxStaleSatisfied(this ILogger logger, TimeSpan age, TimeSpan maxAge) + internal static void ExpirationInfiniteMaxStaleSatisfied(this ILogger logger, TimeSpan age, TimeSpan maxAge) { - _logExpirationInfiniteMaxStaleSatisfied(logger, age, maxAge, null); + _expirationInfiniteMaxStaleSatisfied(logger, age, maxAge, null); } } } diff --git a/src/Middleware/ResponseCaching/src/Internal/ResponseCachingPolicyProvider.cs b/src/Middleware/ResponseCaching/src/Internal/ResponseCachingPolicyProvider.cs index e6f46c9e0f..dc77de80b2 100644 --- a/src/Middleware/ResponseCaching/src/Internal/ResponseCachingPolicyProvider.cs +++ b/src/Middleware/ResponseCaching/src/Internal/ResponseCachingPolicyProvider.cs @@ -17,14 +17,14 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Verify the method if (!HttpMethods.IsGet(request.Method) && !HttpMethods.IsHead(request.Method)) { - context.Logger.LogRequestMethodNotCacheable(request.Method); + context.Logger.RequestMethodNotCacheable(request.Method); return false; } // Verify existence of authorization headers if (!StringValues.IsNullOrEmpty(request.Headers[HeaderNames.Authorization])) { - context.Logger.LogRequestWithAuthorizationNotCacheable(); + context.Logger.RequestWithAuthorizationNotCacheable(); return false; } @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal { if (HeaderUtilities.ContainsCacheDirective(request.Headers[HeaderNames.CacheControl], CacheControlHeaderValue.NoCacheString)) { - context.Logger.LogRequestWithNoCacheNotCacheable(); + context.Logger.RequestWithNoCacheNotCacheable(); return false; } } @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Support for legacy HTTP 1.0 cache directive if (HeaderUtilities.ContainsCacheDirective(request.Headers[HeaderNames.Pragma], CacheControlHeaderValue.NoCacheString)) { - context.Logger.LogRequestWithPragmaNoCacheNotCacheable(); + context.Logger.RequestWithPragmaNoCacheNotCacheable(); return false; } } @@ -70,21 +70,21 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Only cache pages explicitly marked with public if (!HeaderUtilities.ContainsCacheDirective(responseCacheControlHeader, CacheControlHeaderValue.PublicString)) { - context.Logger.LogResponseWithoutPublicNotCacheable(); + context.Logger.ResponseWithoutPublicNotCacheable(); return false; } // Check response no-store if (HeaderUtilities.ContainsCacheDirective(responseCacheControlHeader, CacheControlHeaderValue.NoStoreString)) { - context.Logger.LogResponseWithNoStoreNotCacheable(); + context.Logger.ResponseWithNoStoreNotCacheable(); return false; } // Check no-cache if (HeaderUtilities.ContainsCacheDirective(responseCacheControlHeader, CacheControlHeaderValue.NoCacheString)) { - context.Logger.LogResponseWithNoCacheNotCacheable(); + context.Logger.ResponseWithNoCacheNotCacheable(); return false; } @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Do not cache responses with Set-Cookie headers if (!StringValues.IsNullOrEmpty(response.Headers[HeaderNames.SetCookie])) { - context.Logger.LogResponseWithSetCookieNotCacheable(); + context.Logger.ResponseWithSetCookieNotCacheable(); return false; } @@ -101,21 +101,21 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal var varyHeader = response.Headers[HeaderNames.Vary]; if (varyHeader.Count == 1 && string.Equals(varyHeader, "*", StringComparison.OrdinalIgnoreCase)) { - context.Logger.LogResponseWithVaryStarNotCacheable(); + context.Logger.ResponseWithVaryStarNotCacheable(); return false; } // Check private if (HeaderUtilities.ContainsCacheDirective(responseCacheControlHeader, CacheControlHeaderValue.PrivateString)) { - context.Logger.LogResponseWithPrivateNotCacheable(); + context.Logger.ResponseWithPrivateNotCacheable(); return false; } // Check response code if (response.StatusCode != StatusCodes.Status200OK) { - context.Logger.LogResponseWithUnsuccessfulStatusCodeNotCacheable(response.StatusCode); + context.Logger.ResponseWithUnsuccessfulStatusCodeNotCacheable(response.StatusCode); return false; } @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal !context.ResponseMaxAge.HasValue && context.ResponseTime.Value >= context.ResponseExpires) { - context.Logger.LogExpirationExpiresExceeded(context.ResponseTime.Value, context.ResponseExpires.Value); + context.Logger.ExpirationExpiresExceeded(context.ResponseTime.Value, context.ResponseExpires.Value); return false; } } @@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Validate shared max age if (age >= context.ResponseSharedMaxAge) { - context.Logger.LogExpirationSharedMaxAgeExceeded(age, context.ResponseSharedMaxAge.Value); + context.Logger.ExpirationSharedMaxAgeExceeded(age, context.ResponseSharedMaxAge.Value); return false; } else if (!context.ResponseSharedMaxAge.HasValue) @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Validate max age if (age >= context.ResponseMaxAge) { - context.Logger.LogExpirationMaxAgeExceeded(age, context.ResponseMaxAge.Value); + context.Logger.ExpirationMaxAgeExceeded(age, context.ResponseMaxAge.Value); return false; } else if (!context.ResponseMaxAge.HasValue) @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Validate expiration if (context.ResponseTime.Value >= context.ResponseExpires) { - context.Logger.LogExpirationExpiresExceeded(context.ResponseTime.Value, context.ResponseExpires.Value); + context.Logger.ExpirationExpiresExceeded(context.ResponseTime.Value, context.ResponseExpires.Value); return false; } } @@ -174,7 +174,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal if (HeaderUtilities.TryParseSeconds(requestCacheControlHeaders, CacheControlHeaderValue.MinFreshString, out minFresh)) { age += minFresh.Value; - context.Logger.LogExpirationMinFreshAdded(minFresh.Value); + context.Logger.ExpirationMinFreshAdded(minFresh.Value); } // Validate shared max age, this overrides any max age settings for shared caches @@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal if (age >= cachedSharedMaxAge) { // shared max age implies must revalidate - context.Logger.LogExpirationSharedMaxAgeExceeded(age, cachedSharedMaxAge.Value); + context.Logger.ExpirationSharedMaxAgeExceeded(age, cachedSharedMaxAge.Value); return false; } else if (!cachedSharedMaxAge.HasValue) @@ -203,7 +203,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal if (HeaderUtilities.ContainsCacheDirective(cachedCacheControlHeaders, CacheControlHeaderValue.MustRevalidateString) || HeaderUtilities.ContainsCacheDirective(cachedCacheControlHeaders, CacheControlHeaderValue.ProxyRevalidateString)) { - context.Logger.LogExpirationMustRevalidate(age, lowestMaxAge.Value); + context.Logger.ExpirationMustRevalidate(age, lowestMaxAge.Value); return false; } @@ -214,18 +214,18 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal // Request allows stale values with no age limit if (maxStaleExist && !requestMaxStale.HasValue) { - context.Logger.LogExpirationInfiniteMaxStaleSatisfied(age, lowestMaxAge.Value); + context.Logger.ExpirationInfiniteMaxStaleSatisfied(age, lowestMaxAge.Value); return true; } // Request allows stale values with age limit if (requestMaxStale.HasValue && age - lowestMaxAge < requestMaxStale) { - context.Logger.LogExpirationMaxStaleSatisfied(age, lowestMaxAge.Value, requestMaxStale.Value); + context.Logger.ExpirationMaxStaleSatisfied(age, lowestMaxAge.Value, requestMaxStale.Value); return true; } - context.Logger.LogExpirationMaxAgeExceeded(age, lowestMaxAge.Value); + context.Logger.ExpirationMaxAgeExceeded(age, lowestMaxAge.Value); return false; } else if (!cachedMaxAge.HasValue && !requestMaxAge.HasValue) @@ -235,7 +235,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal if (HeaderUtilities.TryParseDate(context.CachedResponseHeaders[HeaderNames.Expires].ToString(), out expires) && context.ResponseTime.Value >= expires) { - context.Logger.LogExpirationExpiresExceeded(context.ResponseTime.Value, expires); + context.Logger.ExpirationExpiresExceeded(context.ResponseTime.Value, expires); return false; } } diff --git a/src/Middleware/ResponseCaching/src/ResponseCachingMiddleware.cs b/src/Middleware/ResponseCaching/src/ResponseCachingMiddleware.cs index 208d6e998a..d6a744555c 100644 --- a/src/Middleware/ResponseCaching/src/ResponseCachingMiddleware.cs +++ b/src/Middleware/ResponseCaching/src/ResponseCachingMiddleware.cs @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.ResponseCaching // Check conditional request rules if (ContentIsNotModified(context)) { - _logger.LogNotModifiedServed(); + _logger.NotModifiedServed(); context.HttpContext.Response.StatusCode = StatusCodes.Status304NotModified; } else @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.ResponseCaching context.HttpContext.Abort(); } } - _logger.LogCachedResponseServed(); + _logger.CachedResponseServed(); } return true; } @@ -221,12 +221,12 @@ namespace Microsoft.AspNetCore.ResponseCaching if (HeaderUtilities.ContainsCacheDirective(context.HttpContext.Request.Headers[HeaderNames.CacheControl], CacheControlHeaderValue.OnlyIfCachedString)) { - _logger.LogGatewayTimeoutServed(); + _logger.GatewayTimeoutServed(); context.HttpContext.Response.StatusCode = StatusCodes.Status504GatewayTimeout; return true; } - _logger.LogNoResponseServed(); + _logger.NoResponseServed(); return false; } @@ -279,7 +279,7 @@ namespace Microsoft.AspNetCore.ResponseCaching } // Always overwrite the CachedVaryByRules to update the expiry information - _logger.LogVaryByRulesUpdated(normalizedVaryHeaders, normalizedVaryQueryKeys); + _logger.VaryByRulesUpdated(normalizedVaryHeaders, normalizedVaryQueryKeys); storeVaryByEntry = true; context.StorageVaryKey = _keyProvider.CreateStorageVaryByKey(context); @@ -349,12 +349,12 @@ namespace Microsoft.AspNetCore.ResponseCaching } context.CachedResponse.Body = bufferStream; - _logger.LogResponseCached(); + _logger.ResponseCached(); await _cache.SetAsync(context.StorageVaryKey ?? context.BaseKey, context.CachedResponse, context.CachedResponseValidFor); } else { - _logger.LogResponseContentLengthMismatchNotCached(); + _logger.ResponseContentLengthMismatchNotCached(); } } else @@ -453,7 +453,7 @@ namespace Microsoft.AspNetCore.ResponseCaching { if (ifNoneMatchHeader.Count == 1 && StringSegment.Equals(ifNoneMatchHeader[0], EntityTagHeaderValue.Any.Tag, StringComparison.OrdinalIgnoreCase)) { - context.Logger.LogNotModifiedIfNoneMatchStar(); + context.Logger.NotModifiedIfNoneMatchStar(); return true; } @@ -468,7 +468,7 @@ namespace Microsoft.AspNetCore.ResponseCaching var requestETag = ifNoneMatchEtags[i]; if (eTag.Compare(requestETag, useStrongComparison: false)) { - context.Logger.LogNotModifiedIfNoneMatchMatched(requestETag); + context.Logger.NotModifiedIfNoneMatchMatched(requestETag); return true; } } @@ -490,7 +490,7 @@ namespace Microsoft.AspNetCore.ResponseCaching if (HeaderUtilities.TryParseDate(ifModifiedSince.ToString(), out modifiedSince) && modified <= modifiedSince) { - context.Logger.LogNotModifiedIfModifiedSinceSatisfied(modified, modifiedSince); + context.Logger.NotModifiedIfModifiedSinceSatisfied(modified, modifiedSince); return true; } } diff --git a/src/Middleware/ResponseCompression/src/internal/ResponseCompressionLoggingExtensions.cs b/src/Middleware/ResponseCompression/src/internal/ResponseCompressionLoggingExtensions.cs index 75f3d07fd3..bf16682498 100644 --- a/src/Middleware/ResponseCompression/src/internal/ResponseCompressionLoggingExtensions.cs +++ b/src/Middleware/ResponseCompression/src/internal/ResponseCompressionLoggingExtensions.cs @@ -19,14 +19,45 @@ namespace Microsoft.AspNetCore.ResponseCompression.Internal static ResponseCompressionLoggingExtensions() { - _noAcceptEncoding = LoggerMessage.Define(LogLevel.Debug, 1, "No response compression available, the Accept-Encoding header is missing or invalid."); - _noCompressionForHttps = LoggerMessage.Define(LogLevel.Debug, 2, "No response compression available for HTTPS requests. See ResponseCompressionOptions.EnableForHttps."); - _requestAcceptsCompression = LoggerMessage.Define(LogLevel.Trace, 3, "This request accepts compression."); - _noCompressionDueToHeader = LoggerMessage.Define(LogLevel.Debug, 4, "Response compression disabled due to the {header} header."); - _noCompressionForContentType = LoggerMessage.Define(LogLevel.Debug, 5, "Response compression is not enabled for the Content-Type '{header}'."); - _shouldCompressResponse = LoggerMessage.Define(LogLevel.Trace, 6, "Response compression is available for this Content-Type."); - _noCompressionProvider = LoggerMessage.Define(LogLevel.Debug, 7, "No matching response compression provider found."); - _compressWith = LoggerMessage.Define(LogLevel.Debug, 8, "The response will be compressed with '{provider}'."); + _noAcceptEncoding = LoggerMessage.Define( + LogLevel.Debug, + new EventId(1, "NoAcceptEncoding"), + "No response compression available, the Accept-Encoding header is missing or invalid."); + + _noCompressionForHttps = LoggerMessage.Define( + LogLevel.Debug, + new EventId(2, "NoCompressionForHttps"), + "No response compression available for HTTPS requests. See ResponseCompressionOptions.EnableForHttps."); + + _requestAcceptsCompression = LoggerMessage.Define( + LogLevel.Trace, + new EventId(3, "RequestAcceptsCompression"), + "This request accepts compression."); + + _noCompressionDueToHeader = LoggerMessage.Define( + LogLevel.Debug, + new EventId(4, "NoCompressionDueToHeader"), + "Response compression disabled due to the {header} header."); + + _noCompressionForContentType = LoggerMessage.Define( + LogLevel.Debug, + new EventId(5, "NoCompressionForContentType"), + "Response compression is not enabled for the Content-Type '{header}'."); + + _shouldCompressResponse = LoggerMessage.Define( + LogLevel.Trace, + new EventId(6, "ShouldCompressResponse"), + "Response compression is available for this Content-Type."); + + _noCompressionProvider = LoggerMessage.Define( + LogLevel.Debug, + new EventId(7, "NoCompressionProvider"), + "No matching response compression provider found."); + + _compressWith = LoggerMessage.Define( + LogLevel.Debug, + new EventId(8, "CompressWith"), + "The response will be compressed with '{provider}'."); } public static void NoAcceptEncoding(this ILogger logger) diff --git a/src/Middleware/Rewrite/src/Extensions/RewriteMiddlewareLoggingExtensions.cs b/src/Middleware/Rewrite/src/Extensions/RewriteMiddlewareLoggingExtensions.cs index 8b500b4338..4e35fc478c 100644 --- a/src/Middleware/Rewrite/src/Extensions/RewriteMiddlewareLoggingExtensions.cs +++ b/src/Middleware/Rewrite/src/Extensions/RewriteMiddlewareLoggingExtensions.cs @@ -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; @@ -11,14 +11,14 @@ namespace Microsoft.AspNetCore.Rewrite.Logging private static readonly Action _requestContinueResults; private static readonly Action _requestResponseComplete; private static readonly Action _requestStopRules; - private static readonly Action _urlRewriteDidNotMatchRule; + private static readonly Action _urlRewriteNotMatchedRule; private static readonly Action _urlRewriteMatchedRule; - private static readonly Action _modRewriteDidNotMatchRule; + private static readonly Action _modRewriteNotMatchedRule; private static readonly Action _modRewriteMatchedRule; private static readonly Action _redirectedToHttps; private static readonly Action _redirectedToWww; - private static readonly Action _redirectSummary; - private static readonly Action _rewriteSummary; + private static readonly Action _redirectedRequest; + private static readonly Action _rewrittenRequest; private static readonly Action _abortedRequest; private static readonly Action _customResponse; @@ -26,67 +26,67 @@ namespace Microsoft.AspNetCore.Rewrite.Logging { _requestContinueResults = LoggerMessage.Define( LogLevel.Debug, - 1, + new EventId(1, "RequestContinueResults"), "Request is continuing in applying rules. Current url is {currentUrl}"); _requestResponseComplete = LoggerMessage.Define( LogLevel.Debug, - 2, + new EventId(2, "RequestResponseComplete"), "Request is done processing. Location header '{Location}' with status code '{StatusCode}'."); _requestStopRules = LoggerMessage.Define( LogLevel.Debug, - 3, + new EventId(3, "RequestStopRules"), "Request is done applying rules. Url was rewritten to {rewrittenUrl}"); - _urlRewriteDidNotMatchRule = LoggerMessage.Define( + _urlRewriteNotMatchedRule = LoggerMessage.Define( LogLevel.Debug, - 4, + new EventId(4, "UrlRewriteNotMatchedRule"), "Request did not match current rule '{Name}'."); _urlRewriteMatchedRule = LoggerMessage.Define( LogLevel.Debug, - 5, + new EventId(5, "UrlRewriteMatchedRule"), "Request matched current UrlRewriteRule '{Name}'."); - _modRewriteDidNotMatchRule = LoggerMessage.Define( + _modRewriteNotMatchedRule = LoggerMessage.Define( LogLevel.Debug, - 6, + new EventId(6, "ModRewriteNotMatchedRule"), "Request matched current ModRewriteRule."); _modRewriteMatchedRule = LoggerMessage.Define( LogLevel.Debug, - 7, + new EventId(7, "ModRewriteMatchedRule"), "Request matched current ModRewriteRule."); _redirectedToHttps = LoggerMessage.Define( LogLevel.Information, - 8, + new EventId(8, "RedirectedToHttps"), "Request redirected to HTTPS"); - _redirectSummary = LoggerMessage.Define( + _redirectedRequest = LoggerMessage.Define( LogLevel.Information, - 9, + new EventId(9, "RedirectedRequest"), "Request was redirected to {redirectedUrl}"); - _rewriteSummary = LoggerMessage.Define( + _rewrittenRequest = LoggerMessage.Define( LogLevel.Information, - 10, + new EventId(10, "RewritetenRequest"), "Request was rewritten to {rewrittenUrl}"); _abortedRequest = LoggerMessage.Define( LogLevel.Debug, - 11, + new EventId(11, "AbortedRequest"), "Request to {requestedUrl} was aborted"); _customResponse = LoggerMessage.Define( LogLevel.Debug, - 12, + new EventId(12, "CustomResponse"), "Request to {requestedUrl} was ended"); _redirectedToWww = LoggerMessage.Define( LogLevel.Information, - 13, + new EventId(13, "RedirectedToWww"), "Request redirected to www"); } @@ -105,9 +105,9 @@ namespace Microsoft.AspNetCore.Rewrite.Logging _requestStopRules(logger, rewrittenUrl, null); } - public static void UrlRewriteDidNotMatchRule(this ILogger logger, string name) + public static void UrlRewriteNotMatchedRule(this ILogger logger, string name) { - _urlRewriteDidNotMatchRule(logger, name, null); + _urlRewriteNotMatchedRule(logger, name, null); } public static void UrlRewriteMatchedRule(this ILogger logger, string name) @@ -115,9 +115,9 @@ namespace Microsoft.AspNetCore.Rewrite.Logging _urlRewriteMatchedRule(logger, name, null); } - public static void ModRewriteDidNotMatchRule(this ILogger logger) + public static void ModRewriteNotMatchedRule(this ILogger logger) { - _modRewriteDidNotMatchRule(logger, null); + _modRewriteNotMatchedRule(logger, null); } public static void ModRewriteMatchedRule(this ILogger logger) @@ -135,14 +135,14 @@ namespace Microsoft.AspNetCore.Rewrite.Logging _redirectedToWww(logger, null); } - public static void RedirectedSummary(this ILogger logger, string redirectedUrl) + public static void RedirectedRequest(this ILogger logger, string redirectedUrl) { - _redirectSummary(logger, redirectedUrl, null); + _redirectedRequest(logger, redirectedUrl, null); } - public static void RewriteSummary(this ILogger logger, string rewrittenUrl) + public static void RewrittenRequest(this ILogger logger, string rewrittenUrl) { - _rewriteSummary(logger, rewrittenUrl, null); + _rewrittenRequest(logger, rewrittenUrl, null); } public static void AbortedRequest(this ILogger logger, string requestedUrl) diff --git a/src/Middleware/Rewrite/src/Internal/ApacheModRewrite/ApacheModRewriteRule.cs b/src/Middleware/Rewrite/src/Internal/ApacheModRewrite/ApacheModRewriteRule.cs index 03b3a1ab6c..32be7fe80d 100644 --- a/src/Middleware/Rewrite/src/Internal/ApacheModRewrite/ApacheModRewriteRule.cs +++ b/src/Middleware/Rewrite/src/Internal/ApacheModRewrite/ApacheModRewriteRule.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite if (!initMatchRes.Success) { - context.Logger?.ModRewriteDidNotMatchRule(); + 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?.ModRewriteDidNotMatchRule(); + context.Logger?.ModRewriteNotMatchedRule(); return; } } diff --git a/src/Middleware/Rewrite/src/Internal/IISUrlRewrite/IISUrlRewriteRule.cs b/src/Middleware/Rewrite/src/Internal/IISUrlRewrite/IISUrlRewriteRule.cs index 678486d592..4636c2187c 100644 --- a/src/Middleware/Rewrite/src/Internal/IISUrlRewrite/IISUrlRewriteRule.cs +++ b/src/Middleware/Rewrite/src/Internal/IISUrlRewrite/IISUrlRewriteRule.cs @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite if (!initMatchResults.Success) { - context.Logger?.UrlRewriteDidNotMatchRule(Name); + context.Logger?.UrlRewriteNotMatchedRule(Name); return; } @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite condResult = ConditionEvaluator.Evaluate(Conditions, context, initMatchResults.BackReferences); if (!condResult.Success) { - context.Logger?.UrlRewriteDidNotMatchRule(Name); + context.Logger?.UrlRewriteNotMatchedRule(Name); return; } } diff --git a/src/Middleware/Rewrite/src/Internal/RedirectRule.cs b/src/Middleware/Rewrite/src/Internal/RedirectRule.cs index 1c5efaa581..000dcfef1e 100644 --- a/src/Middleware/Rewrite/src/Internal/RedirectRule.cs +++ b/src/Middleware/Rewrite/src/Internal/RedirectRule.cs @@ -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; @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal response.Headers[HeaderNames.Location] = pathBase + newPath + context.HttpContext.Request.QueryString; } - context.Logger?.RedirectedSummary(newPath); + context.Logger?.RedirectedRequest(newPath); } } } diff --git a/src/Middleware/Rewrite/src/Internal/RewriteRule.cs b/src/Middleware/Rewrite/src/Internal/RewriteRule.cs index d9e0050857..f33f3a2b40 100644 --- a/src/Middleware/Rewrite/src/Internal/RewriteRule.cs +++ b/src/Middleware/Rewrite/src/Internal/RewriteRule.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal } } - context.Logger?.RewriteSummary(result); + context.Logger?.RewrittenRequest(result); } } } diff --git a/src/Middleware/Session/src/LoggingExtensions.cs b/src/Middleware/Session/src/LoggingExtensions.cs index 2552ac20de..60b2db52c9 100644 --- a/src/Middleware/Session/src/LoggingExtensions.cs +++ b/src/Middleware/Session/src/LoggingExtensions.cs @@ -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; @@ -23,51 +23,51 @@ namespace Microsoft.Extensions.Logging static LoggingExtensions() { _errorClosingTheSession = LoggerMessage.Define( - eventId: 1, + eventId: new EventId(1, "ErrorClosingTheSession"), logLevel: LogLevel.Error, formatString: "Error closing the session."); _accessingExpiredSession = LoggerMessage.Define( - eventId: 2, + eventId: new EventId(2, "AccessingExpiredSession"), logLevel: LogLevel.Information, formatString: "Accessing expired session, Key:{sessionKey}"); _sessionStarted = LoggerMessage.Define( - eventId: 3, + eventId: new EventId(3, "SessionStarted"), logLevel: LogLevel.Information, formatString: "Session started; Key:{sessionKey}, Id:{sessionId}"); _sessionLoaded = LoggerMessage.Define( - eventId: 4, + eventId: new EventId(4, "SessionLoaded"), logLevel: LogLevel.Debug, formatString: "Session loaded; Key:{sessionKey}, Id:{sessionId}, Count:{count}"); _sessionStored = LoggerMessage.Define( - eventId: 5, + eventId: new EventId(5, "SessionStored"), logLevel: LogLevel.Debug, formatString: "Session stored; Key:{sessionKey}, Id:{sessionId}, Count:{count}"); _sessionCacheReadException = LoggerMessage.Define( - eventId: 6, + eventId: new EventId(6, "SessionCacheReadException"), logLevel: LogLevel.Error, formatString: "Session cache read exception, Key:{sessionKey}"); _errorUnprotectingCookie = LoggerMessage.Define( - eventId: 7, + eventId: new EventId(7, "ErrorUnprotectingCookie"), logLevel: LogLevel.Warning, formatString: "Error unprotecting the session cookie."); _sessionLoadingTimeout = LoggerMessage.Define( - eventId: 8, + eventId: new EventId(8, "SessionLoadingTimeout"), logLevel: LogLevel.Warning, formatString: "Loading the session timed out."); _sessionCommitTimeout = LoggerMessage.Define( - eventId: 9, + eventId: new EventId(9, "SessionCommitTimeout"), logLevel: LogLevel.Warning, formatString: "Committing the session timed out."); _sessionCommitCanceled = LoggerMessage.Define( - eventId: 10, + eventId: new EventId(10, "SessionCommitCanceled"), logLevel: LogLevel.Information, formatString: "Committing the session was canceled."); _sessionRefreshTimeout = LoggerMessage.Define( - eventId: 11, + eventId: new EventId(11, "SessionRefreshTimeout"), logLevel: LogLevel.Warning, formatString: "Refreshing the session timed out."); _sessionRefreshCanceled = LoggerMessage.Define( - eventId: 12, + eventId: new EventId(12, "SessionRefreshCanceled"), logLevel: LogLevel.Information, formatString: "Refreshing the session was canceled."); }