-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use LoggerMessage.Define in HttpSys (#31333)
- Use LoggerMessage.Define() throughout HttpSys instead of ILogger extension methods. - Also updates two incorrect event Id field names. Fixes #31313.
- Loading branch information
1 parent
223541c
commit 020745c
Showing
21 changed files
with
534 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// 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; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.AspNetCore.Server.HttpSys | ||
{ | ||
internal partial class HttpSysListener | ||
{ | ||
private static class Log | ||
{ | ||
private static readonly Action<ILogger, Exception?> _listenerDisposeError = | ||
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.ListenerDisposeError, "Dispose"); | ||
|
||
private static readonly Action<ILogger, Exception?> _listenerDisposing = | ||
LoggerMessage.Define(LogLevel.Trace, LoggerEventIds.ListenerDisposing, "Disposing the listener."); | ||
|
||
private static readonly Action<ILogger, Exception?> _httpSysListenerCtorError = | ||
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.HttpSysListenerCtorError, ".Ctor"); | ||
|
||
private static readonly Action<ILogger, Exception?> _listenerStartError = | ||
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.ListenerStartError, "Start"); | ||
|
||
private static readonly Action<ILogger, Exception?> _listenerStarting = | ||
LoggerMessage.Define(LogLevel.Trace, LoggerEventIds.ListenerStarting, "Starting the listener."); | ||
|
||
private static readonly Action<ILogger, Exception?> _listenerStopError = | ||
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.ListenerStopError, "Stop"); | ||
|
||
private static readonly Action<ILogger, Exception?> _listenerStopping = | ||
LoggerMessage.Define(LogLevel.Trace, LoggerEventIds.ListenerStopping, "Stopping the listener."); | ||
|
||
private static readonly Action<ILogger, ulong, Exception?> _requestValidationFailed = | ||
LoggerMessage.Define<ulong>(LogLevel.Error, LoggerEventIds.RequestValidationFailed, "Error validating request {RequestId}"); | ||
|
||
public static void ListenerDisposeError(ILogger logger, Exception exception) | ||
{ | ||
_listenerDisposeError(logger, exception); | ||
} | ||
|
||
public static void ListenerDisposing(ILogger logger) | ||
{ | ||
_listenerDisposing(logger, null); | ||
} | ||
|
||
public static void HttpSysListenerCtorError(ILogger logger, Exception exception) | ||
{ | ||
_httpSysListenerCtorError(logger, exception); | ||
} | ||
|
||
public static void ListenerStartError(ILogger logger, Exception exception) | ||
{ | ||
_listenerStartError(logger, exception); | ||
} | ||
|
||
public static void ListenerStarting(ILogger logger) | ||
{ | ||
_listenerStarting(logger, null); | ||
} | ||
|
||
public static void ListenerStopError(ILogger logger, Exception exception) | ||
{ | ||
_listenerStopError(logger, exception); | ||
} | ||
|
||
public static void ListenerStopping(ILogger logger) | ||
{ | ||
_listenerStopping(logger, null); | ||
} | ||
|
||
public static void RequestValidationFailed(ILogger logger, Exception exception, ulong requestId) | ||
{ | ||
_requestValidationFailed(logger, requestId, exception); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Hosting.Server.Features; | ||
using Microsoft.AspNetCore.HttpSys.Internal; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.AspNetCore.Server.HttpSys | ||
{ | ||
internal partial class MessagePump | ||
{ | ||
private static class Log | ||
{ | ||
private static readonly Action<ILogger, Exception?> _acceptError = | ||
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.AcceptError, "Failed to accept a request."); | ||
|
||
private static readonly Action<ILogger, Exception?> _acceptErrorStopping = | ||
LoggerMessage.Define(LogLevel.Debug, LoggerEventIds.AcceptErrorStopping, "Failed to accept a request, the server is stopping."); | ||
|
||
private static readonly Action<ILogger, Exception?> _bindingToDefault = | ||
LoggerMessage.Define(LogLevel.Debug, LoggerEventIds.BindingToDefault, $"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); | ||
|
||
private static readonly Action<ILogger, string, Exception?> _clearedAddresses = | ||
LoggerMessage.Define<string>(LogLevel.Warning, LoggerEventIds.ClearedAddresses, $"Overriding address(es) '{{ServerAddresses)}}'. Binding to endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} instead."); | ||
|
||
private static readonly Action<ILogger, string, Exception?> _clearedPrefixes = | ||
LoggerMessage.Define<string>(LogLevel.Warning, LoggerEventIds.ClearedPrefixes, $"Overriding endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true. Binding to address(es) '{{ServerAddresses}}' instead. "); | ||
|
||
private static readonly Action<ILogger, Exception?> _requestListenerProcessError = | ||
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.RequestListenerProcessError, "ProcessRequestAsync"); | ||
|
||
private static readonly Action<ILogger, int, Exception?> _stopCancelled = | ||
LoggerMessage.Define<int>(LogLevel.Information, LoggerEventIds.StopCancelled, "Canceled, terminating {OutstandingRequests} request(s)."); | ||
|
||
private static readonly Action<ILogger, int, Exception?> _waitingForRequestsToDrain = | ||
LoggerMessage.Define<int>(LogLevel.Information, LoggerEventIds.WaitingForRequestsToDrain, "Stopping, waiting for {OutstandingRequests} request(s) to drain."); | ||
|
||
public static void AcceptError(ILogger logger, Exception exception) | ||
{ | ||
_acceptError(logger, exception); | ||
} | ||
|
||
public static void AcceptErrorStopping(ILogger logger, Exception exception) | ||
{ | ||
_acceptErrorStopping(logger, exception); | ||
} | ||
|
||
public static void BindingToDefault(ILogger logger) | ||
{ | ||
_bindingToDefault(logger, null); | ||
} | ||
|
||
public static void ClearedAddresses(ILogger logger, ICollection<string> serverAddresses) | ||
{ | ||
if (logger.IsEnabled(LogLevel.Warning)) | ||
{ | ||
_clearedAddresses(logger, string.Join(", ", serverAddresses), null); | ||
} | ||
} | ||
|
||
public static void ClearedPrefixes(ILogger logger, ICollection<string> serverAddresses) | ||
{ | ||
if (logger.IsEnabled(LogLevel.Warning)) | ||
{ | ||
_clearedPrefixes(logger, string.Join(", ", serverAddresses), null); | ||
} | ||
} | ||
|
||
public static void RequestListenerProcessError(ILogger logger, Exception exception) | ||
{ | ||
_requestListenerProcessError(logger, exception); | ||
} | ||
|
||
public static void StopCancelled(ILogger logger, int outstandingRequests) | ||
{ | ||
_stopCancelled(logger, outstandingRequests, null); | ||
} | ||
|
||
public static void WaitingForRequestsToDrain(ILogger logger, int outstandingRequests) | ||
{ | ||
_waitingForRequestsToDrain(logger, outstandingRequests, null); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.