Added Log events for Httpsys (#18551)

This commit is contained in:
kunal mehta 2020-02-06 00:24:37 +05:30 committed by GitHub
parent 264fb6a1c9
commit 801578fe19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 115 additions and 57 deletions

View File

@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
_requestQueue?.Dispose(); _requestQueue?.Dispose();
_urlGroup?.Dispose(); _urlGroup?.Dispose();
_serverSession?.Dispose(); _serverSession?.Dispose();
Logger.LogError(0, exception, ".Ctor"); Logger.LogError(LoggerEventIds.HttpSysListenerCtorError, exception, ".Ctor");
throw; throw;
} }
} }
@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
CheckDisposed(); CheckDisposed();
Logger.LogTrace("Starting the listener."); Logger.LogTrace(LoggerEventIds.ListenerStarting, "Starting the listener.");
// Make sure there are no race conditions between Start/Stop/Abort/Close/Dispose. // Make sure there are no race conditions between Start/Stop/Abort/Close/Dispose.
// Start needs to setup all resources. Abort/Stop must not interfere while Start is // Start needs to setup all resources. Abort/Stop must not interfere while Start is
@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
// Make sure the HttpListener instance can't be used if Start() failed. // Make sure the HttpListener instance can't be used if Start() failed.
_state = State.Disposed; _state = State.Disposed;
DisposeInternal(); DisposeInternal();
Logger.LogError(0, exception, "Start"); Logger.LogError(LoggerEventIds.ListenerStartError, exception, "Start");
throw; throw;
} }
} }
@ -195,7 +195,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
return; return;
} }
Logger.LogTrace("Stopping the listener."); Logger.LogTrace(LoggerEventIds.ListenerStopping,"Stopping the listener.");
// If this instance created the queue then remove the URL prefixes before shutting down. // If this instance created the queue then remove the URL prefixes before shutting down.
if (_requestQueue.Created) if (_requestQueue.Created)
@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception exception) catch (Exception exception)
{ {
Logger.LogError(0, exception, "Stop"); Logger.LogError(LoggerEventIds.ListenerStopError, exception, "Stop");
throw; throw;
} }
} }
@ -238,14 +238,14 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
return; return;
} }
Logger.LogTrace("Disposing the listener."); Logger.LogTrace(LoggerEventIds.ListenerDisposing, "Disposing the listener.");
Stop(); Stop();
DisposeInternal(); DisposeInternal();
} }
catch (Exception exception) catch (Exception exception)
{ {
Logger.LogError(0, exception, "Dispose"); Logger.LogError(LoggerEventIds.ListenerDisposeError, exception, "Dispose");
throw; throw;
} }
finally finally
@ -300,7 +300,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception exception) catch (Exception exception)
{ {
Logger.LogError(0, exception, "GetContextAsync"); Logger.LogError(LoggerEventIds.AcceptError, exception, "AcceptAsync");
throw; throw;
} }

View File

@ -0,0 +1,58 @@
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.HttpSys
{
internal static class LoggerEventIds
{
public static EventId HttpSysListenerCtorError = new EventId(1, "HttpSysListenerCtorError");
public static EventId BindingToDefault = new EventId(2, "BindingToDefault");
public static EventId ClearedPrefixes = new EventId(3, "ClearedPrefixes");
public static EventId AcceptErrorStopping = new EventId(4, "AcceptErrorStopping");
public static EventId AcceptError = new EventId(5, "AcceptError");
public static EventId RequestProcessError = new EventId(6, "RequestProcessError");
public static EventId RequestsDrained = new EventId(7, "RequestsDrained");
public static EventId StopCancelled = new EventId(8, "StopCancelled");
public static EventId WaitingForRequestsToDrain = new EventId(9, "WaitingForRequestsToDrain");
public static EventId DisconnectRegistrationError = new EventId(10, "DisconnectRegistrationError");
public static EventId RegisterDisconnectListener = new EventId(11, "RegisterDisconnectListener");
public static EventId UnknownDisconnectError = new EventId(12, "UnknownDisconnectError");
public static EventId DisconnectHandlerError = new EventId(13, "DisconnectHandlerError");
public static EventId ListenerStarting = new EventId(14, "ListenerStarting");
public static EventId ListenerDisposeError = new EventId(15, "ListenerDisposeError");
public static EventId RequestListenerProcessError = new EventId(16, "RequestListenerProcessError");
public static EventId AttachedToQueue = new EventId(17, "AttachedToQueue");
public static EventId SetUrlPropertyError = new EventId(18, "SetUrlPropertyError");
public static EventId RegisteringPrefix = new EventId(19, "RegisteringPrefix");
public static EventId UnregisteringPrefix = new EventId(20, "UnregisteringPrefix");
public static EventId CloseUrlGroupError = new EventId(21, "CloseUrlGroupError");
public static EventId ChannelBindingUnSupported = new EventId(22, "ChannelBindingUnSupported");
public static EventId ChannelBindingMissing = new EventId(23, "ChannelBindingMissing");
public static EventId RequestError = new EventId(24, "RequestError");
public static EventId ErrorInReadingCertificate = new EventId(25, "ErrorInReadingCertificate");
public static EventId ChannelBindingNeedsHttps = new EventId(26, "ChannelBindingNeedsHttps");
public static EventId ChannelBindingRetrived = new EventId(27, "ChannelBindingRetrived");
public static EventId AbortError = new EventId(28, "AbortError");
public static EventId ErrorWhileRead = new EventId(29, "ErrorWhileRead");
public static EventId ErrorWhenReadBegun = new EventId(30, "ErrorWhenReadBegun");
public static EventId ErrorWhenReadAsync = new EventId(31, "ErrorWhenReadAsync");
public static EventId ErrorWhenFlushAsync = new EventId(32, "ErrorWhenFlushAsync");
public static EventId FewerBytesThanExpected = new EventId(33, "FewerBytesThanExpected");
public static EventId WriteError = new EventId(34, "WriteError");
public static EventId WriteErrorIgnored = new EventId(35, "WriteFlushedIgnored");
public static EventId WriteFlushCancelled = new EventId(36, "WriteFlushCancelled");
public static EventId ClearedAddresses = new EventId(37, "ClearedAddresses");
public static EventId FileSendAsyncError = new EventId(38, "FileSendAsyncError");
public static EventId FileSendAsyncCancelled = new EventId(39, "FileSendAsyncCancelled");
public static EventId FileSendAsyncErrorIgnored = new EventId(40, "FileSendAsyncErrorIgnored");
public static EventId WriteCancelled = new EventId(41, "WriteCancelled");
public static EventId ListenerStopping = new EventId(42, "ListenerStopping");
public static EventId ListenerStartError = new EventId(43, "ListenerStartError");
public static EventId DisconnectTriggered = new EventId(44, "DisconnectTriggered");
public static EventId ListenerStopError = new EventId(45, "ListenerStopError");
public static EventId ListenerDisposing = new EventId(46, "ListenerDisposing");
}
}

View File

@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (_options.UrlPrefixes.Count > 0) if (_options.UrlPrefixes.Count > 0)
{ {
_logger.LogWarning($"Overriding endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true." + _logger.LogWarning(LoggerEventIds.ClearedPrefixes, $"Overriding endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true." +
$" Binding to address(es) '{string.Join(", ", _serverAddresses.Addresses)}' instead. "); $" Binding to address(es) '{string.Join(", ", _serverAddresses.Addresses)}' instead. ");
Listener.Options.UrlPrefixes.Clear(); Listener.Options.UrlPrefixes.Clear();
@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (hostingUrlsPresent) if (hostingUrlsPresent)
{ {
_logger.LogWarning($"Overriding address(es) '{string.Join(", ", _serverAddresses.Addresses)}'. " + _logger.LogWarning(LoggerEventIds.ClearedAddresses, $"Overriding address(es) '{string.Join(", ", _serverAddresses.Addresses)}'. " +
$"Binding to endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} instead."); $"Binding to endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} instead.");
_serverAddresses.Addresses.Clear(); _serverAddresses.Addresses.Clear();
@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
else if (Listener.RequestQueue.Created) else if (Listener.RequestQueue.Created)
{ {
_logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); _logger.LogDebug(LoggerEventIds.BindingToDefault, $"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default.");
Listener.Options.UrlPrefixes.Add(Constants.DefaultServerAddress); Listener.Options.UrlPrefixes.Add(Constants.DefaultServerAddress);
} }
@ -171,11 +171,11 @@ namespace Microsoft.AspNetCore.Server.HttpSys
Contract.Assert(Stopping); Contract.Assert(Stopping);
if (Stopping) if (Stopping)
{ {
_logger.LogDebug(0, exception, "ListenForNextRequestAsync-Stopping"); _logger.LogDebug(LoggerEventIds.AcceptErrorStopping, exception, "Failed to accept a request, the server is stopping.");
} }
else else
{ {
_logger.LogError(0, exception, "ListenForNextRequestAsync"); _logger.LogError(LoggerEventIds.AcceptError, exception, "Failed to accept a request.");
} }
continue; continue;
} }
@ -187,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
// Request processing failed to be queued in threadpool // Request processing failed to be queued in threadpool
// Log the error message, release throttle and move on // Log the error message, release throttle and move on
_logger.LogError(0, ex, "ProcessRequestAsync"); _logger.LogError(LoggerEventIds.RequestListenerProcessError, ex, "ProcessRequestAsync");
} }
} }
Interlocked.Decrement(ref _acceptorCounts); Interlocked.Decrement(ref _acceptorCounts);
@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(0, ex, "ProcessRequestAsync"); _logger.LogError(LoggerEventIds.RequestProcessError, ex, "ProcessRequestAsync");
_application.DisposeContext(context, ex); _application.DisposeContext(context, ex);
if (requestContext.Response.HasStarted) if (requestContext.Response.HasStarted)
{ {
@ -247,14 +247,14 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (Interlocked.Decrement(ref _outstandingRequests) == 0 && Stopping) if (Interlocked.Decrement(ref _outstandingRequests) == 0 && Stopping)
{ {
_logger.LogInformation("All requests drained."); _logger.LogInformation(LoggerEventIds.RequestsDrained, "All requests drained.");
_shutdownSignal.TrySetResult(0); _shutdownSignal.TrySetResult(0);
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(0, ex, "ProcessRequestAsync"); _logger.LogError(LoggerEventIds.RequestError, ex, "ProcessRequestAsync");
requestContext.Abort(); requestContext.Abort();
} }
} }
@ -274,7 +274,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (Interlocked.Exchange(ref _shutdownSignalCompleted, 1) == 0) if (Interlocked.Exchange(ref _shutdownSignalCompleted, 1) == 0)
{ {
_logger.LogInformation("Canceled, terminating " + _outstandingRequests + " request(s)."); _logger.LogInformation(LoggerEventIds.StopCancelled, "Canceled, terminating " + _outstandingRequests + " request(s).");
_shutdownSignal.TrySetResult(null); _shutdownSignal.TrySetResult(null);
} }
}); });
@ -292,7 +292,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
// Wait for active requests to drain // Wait for active requests to drain
if (_outstandingRequests > 0) if (_outstandingRequests > 0)
{ {
_logger.LogInformation("Stopping, waiting for " + _outstandingRequests + " request(s) to drain."); _logger.LogInformation(LoggerEventIds.WaitingForRequestsToDrain, "Stopping, waiting for " + _outstandingRequests + " request(s) to drain.");
RegisterCancelation(); RegisterCancelation();
} }
else else

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Win32Exception exception) catch (Win32Exception exception)
{ {
_logger.LogError(0, exception, "GetConnectionToken"); _logger.LogError(LoggerEventIds.DisconnectRegistrationError, exception, "Unable to register for disconnect notifications.");
return CancellationToken.None; return CancellationToken.None;
} }
} }
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
private unsafe CancellationToken CreateDisconnectToken(ulong connectionId) private unsafe CancellationToken CreateDisconnectToken(ulong connectionId)
{ {
_logger.LogDebug("CreateDisconnectToken; Registering connection for disconnect for connection ID: " + connectionId); _logger.LogDebug(LoggerEventIds.RegisterDisconnectListener, "CreateDisconnectToken; Registering connection for disconnect for connection ID: {0}" , connectionId);
// Create a nativeOverlapped callback so we can register for disconnect callback // Create a nativeOverlapped callback so we can register for disconnect callback
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
nativeOverlapped = new SafeNativeOverlapped(boundHandle, boundHandle.AllocateNativeOverlapped( nativeOverlapped = new SafeNativeOverlapped(boundHandle, boundHandle.AllocateNativeOverlapped(
(errorCode, numBytes, overlappedPtr) => (errorCode, numBytes, overlappedPtr) =>
{ {
_logger.LogDebug("CreateDisconnectToken; http.sys disconnect callback fired for connection ID: " + connectionId); _logger.LogDebug(LoggerEventIds.DisconnectTriggered, "CreateDisconnectToken; http.sys disconnect callback fired for connection ID: {0}" , connectionId);
// Free the overlapped // Free the overlapped
nativeOverlapped.Dispose(); nativeOverlapped.Dispose();
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
_logger.LogError(0, exception, "CreateDisconnectToken Callback"); _logger.LogError(LoggerEventIds.DisconnectHandlerError, exception, "CreateDisconnectToken Callback");
} }
}, },
null, null)); null, null));
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
catch (Win32Exception exception) catch (Win32Exception exception)
{ {
statusCode = (uint)exception.NativeErrorCode; statusCode = (uint)exception.NativeErrorCode;
_logger.LogError(0, exception, "CreateDisconnectToken"); _logger.LogError(LoggerEventIds.DisconnectRegistrationError, exception, "CreateDisconnectToken");
} }
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_IO_PENDING && if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_IO_PENDING &&
@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
nativeOverlapped.Dispose(); nativeOverlapped.Dispose();
ConnectionCancellation ignored; ConnectionCancellation ignored;
_connectionCancellationTokens.TryRemove(connectionId, out ignored); _connectionCancellationTokens.TryRemove(connectionId, out ignored);
_logger.LogDebug(0, new Win32Exception((int)statusCode), "HttpWaitForDisconnectEx"); _logger.LogDebug(LoggerEventIds.UnknownDisconnectError, new Win32Exception((int)statusCode), "HttpWaitForDisconnectEx");
cts.Cancel(); cts.Cancel();
} }

View File

@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
if (!Created) if (!Created)
{ {
_logger.LogInformation("Attached to an existing request queue '{requestQueueName}', some options do not apply.", requestQueueName); _logger.LogInformation(LoggerEventIds.AttachedToQueue, "Attached to an existing request queue '{requestQueueName}', some options do not apply.", requestQueueName);
} }
} }

View File

@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS) if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
{ {
var exception = new HttpSysException((int)statusCode); var exception = new HttpSysException((int)statusCode);
_logger.LogError(0, exception, "SetUrlGroupProperty"); _logger.LogError(LoggerEventIds.SetUrlPropertyError, exception, "SetUrlGroupProperty");
if (throwOnError) if (throwOnError)
{ {
throw exception; throw exception;
@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
internal void RegisterPrefix(string uriPrefix, int contextId) internal void RegisterPrefix(string uriPrefix, int contextId)
{ {
_logger.LogDebug("Listening on prefix: " + uriPrefix); _logger.LogDebug(LoggerEventIds.RegisteringPrefix, "Listening on prefix: {0}" , uriPrefix);
CheckDisposed(); CheckDisposed();
var statusCode = HttpApi.HttpAddUrlToUrlGroup(Id, uriPrefix, (ulong)contextId, 0); var statusCode = HttpApi.HttpAddUrlToUrlGroup(Id, uriPrefix, (ulong)contextId, 0);
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
internal bool UnregisterPrefix(string uriPrefix) internal bool UnregisterPrefix(string uriPrefix)
{ {
_logger.LogInformation("Stop listening on prefix: " + uriPrefix); _logger.LogInformation(LoggerEventIds.UnregisteringPrefix, "Stop listening on prefix: {0}" , uriPrefix);
CheckDisposed(); CheckDisposed();
var statusCode = HttpApi.HttpRemoveUrlFromUrlGroup(Id, uriPrefix, 0); var statusCode = HttpApi.HttpRemoveUrlFromUrlGroup(Id, uriPrefix, 0);
@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS) if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
{ {
_logger.LogError("CleanupV2Config; Result: " + statusCode); _logger.LogError(LoggerEventIds.CloseUrlGroupError, "HttpCloseUrlGroup; Result: {0}" , statusCode);
} }
Id = 0; Id = 0;
} }

View File

@ -400,13 +400,13 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
else if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_INVALID_PARAMETER) else if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_INVALID_PARAMETER)
{ {
logger.LogError("GetChannelBindingFromTls; Channel binding is not supported."); logger.LogError(LoggerEventIds.ChannelBindingUnSupported, "GetChannelBindingFromTls; Channel binding is not supported.");
return null; // old schannel library which doesn't support CBT return null; // old schannel library which doesn't support CBT
} }
else else
{ {
// It's up to the consumer to fail if the missing ChannelBinding matters to them. // It's up to the consumer to fail if the missing ChannelBinding matters to them.
logger.LogError(0, new HttpSysException((int)statusCode), "GetChannelBindingFromTls"); logger.LogError(LoggerEventIds.ChannelBindingMissing, new HttpSysException((int)statusCode), "GetChannelBindingFromTls");
break; break;
} }
} }

View File

@ -338,11 +338,11 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (CryptographicException ce) catch (CryptographicException ce)
{ {
RequestContext.Logger.LogDebug(ce, "An error occurred reading the client certificate."); RequestContext.Logger.LogDebug(LoggerEventIds.ErrorInReadingCertificate, ce, "An error occurred reading the client certificate.");
} }
catch (SecurityException se) catch (SecurityException se)
{ {
RequestContext.Logger.LogDebug(se, "An error occurred reading the client certificate."); RequestContext.Logger.LogDebug(LoggerEventIds.ErrorInReadingCertificate, se, "An error occurred reading the client certificate.");
} }
} }

View File

@ -120,14 +120,14 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (!Request.IsHttps) if (!Request.IsHttps)
{ {
Logger.LogDebug("TryGetChannelBinding; Channel binding requires HTTPS."); Logger.LogDebug(LoggerEventIds.ChannelBindingNeedsHttps,"TryGetChannelBinding; Channel binding requires HTTPS.");
return false; return false;
} }
value = ClientCertLoader.GetChannelBindingFromTls(Server.RequestQueue, Request.UConnectionId, Logger); value = ClientCertLoader.GetChannelBindingFromTls(Server.RequestQueue, Request.UConnectionId, Logger);
Debug.Assert(value != null, "GetChannelBindingFromTls returned null even though OS supposedly supports Extended Protection"); Debug.Assert(value != null, "GetChannelBindingFromTls returned null even though OS supposedly supports Extended Protection");
Logger.LogInformation("Channel binding retrieved."); Logger.LogDebug(LoggerEventIds.ChannelBindingRetrived,"Channel binding retrieved.");
return value != null; return value != null;
} }
@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogDebug(0, ex, "Abort"); Logger.LogDebug(LoggerEventIds.AbortError, ex, "Abort");
} }
_requestAbortSource.Dispose(); _requestAbortSource.Dispose();
} }

View File

@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS && statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_HANDLE_EOF) if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS && statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_HANDLE_EOF)
{ {
Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode)); Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode));
Logger.LogError(0, exception, "Read"); Logger.LogError(LoggerEventIds.ErrorWhileRead, exception, "Read");
Abort(); Abort();
throw exception; throw exception;
} }
@ -242,7 +242,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception e) catch (Exception e)
{ {
Logger.LogError(0, e, "BeginRead"); Logger.LogError(LoggerEventIds.ErrorWhenReadBegun, e, "BeginRead");
asyncResult.Dispose(); asyncResult.Dispose();
throw; throw;
} }
@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
else else
{ {
Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode)); Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode));
Logger.LogError(0, exception, "BeginRead"); Logger.LogError(LoggerEventIds.ErrorWhenReadBegun, exception, "BeginRead");
Abort(); Abort();
throw exception; throw exception;
} }
@ -365,7 +365,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
asyncResult.Dispose(); asyncResult.Dispose();
Abort(); Abort();
Logger.LogError(0, e, "ReadAsync"); Logger.LogError(LoggerEventIds.ErrorWhenReadAsync, e, "ReadAsync");
throw; throw;
} }
@ -386,7 +386,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
else else
{ {
Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode)); Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode));
Logger.LogError(0, exception, "ReadAsync"); Logger.LogError(LoggerEventIds.ErrorWhenReadAsync, exception, "ReadAsync");
Abort(); Abort();
throw exception; throw exception;
} }

View File

@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
if (!RequestContext.DisconnectToken.IsCancellationRequested) if (!RequestContext.DisconnectToken.IsCancellationRequested)
{ {
// This is logged rather than thrown because it is too late for an exception to be visible in user code. // This is logged rather than thrown because it is too late for an exception to be visible in user code.
Logger.LogError("ResponseStream::Dispose; Fewer bytes were written than were specified in the Content-Length."); Logger.LogError(LoggerEventIds.FewerBytesThanExpected, "ResponseStream::Dispose; Fewer bytes were written than were specified in the Content-Length.");
} }
_requestContext.Abort(); _requestContext.Abort();
return; return;
@ -175,14 +175,14 @@ namespace Microsoft.AspNetCore.Server.HttpSys
if (ThrowWriteExceptions) if (ThrowWriteExceptions)
{ {
var exception = new IOException(string.Empty, new HttpSysException((int)statusCode)); var exception = new IOException(string.Empty, new HttpSysException((int)statusCode));
Logger.LogError(0, exception, "Flush"); Logger.LogError(LoggerEventIds.WriteError, exception, "Flush");
Abort(); Abort();
throw exception; throw exception;
} }
else else
{ {
// Abort the request but do not close the stream, let future writes complete silently // Abort the request but do not close the stream, let future writes complete silently
Logger.LogDebug($"Flush; Ignored write exception: {statusCode}"); Logger.LogDebug(LoggerEventIds.WriteErrorIgnored, $"Flush; Ignored write exception: {statusCode}");
Abort(dispose: false); Abort(dispose: false);
} }
} }
@ -345,7 +345,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception e) catch (Exception e)
{ {
Logger.LogError(0, e, "FlushAsync"); Logger.LogError(LoggerEventIds.ErrorWhenFlushAsync, e, "FlushAsync");
asyncResult.Dispose(); asyncResult.Dispose();
Abort(); Abort();
throw; throw;
@ -355,21 +355,21 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
Logger.LogDebug($"FlushAsync; Write cancelled with error code: {statusCode}"); Logger.LogDebug(LoggerEventIds.WriteFlushCancelled,$"FlushAsync; Write cancelled with error code: {statusCode}");
asyncResult.Cancel(ThrowWriteExceptions); asyncResult.Cancel(ThrowWriteExceptions);
} }
else if (ThrowWriteExceptions) else if (ThrowWriteExceptions)
{ {
asyncResult.Dispose(); asyncResult.Dispose();
Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode)); Exception exception = new IOException(string.Empty, new HttpSysException((int)statusCode));
Logger.LogError(0, exception, "FlushAsync"); Logger.LogError(LoggerEventIds.ErrorWhenFlushAsync, exception, "FlushAsync");
Abort(); Abort();
throw exception; throw exception;
} }
else else
{ {
// Abort the request but do not close the stream, let future writes complete silently // Abort the request but do not close the stream, let future writes complete silently
Logger.LogDebug($"FlushAsync; Ignored write exception: {statusCode}"); Logger.LogDebug(LoggerEventIds.WriteErrorIgnored,$"FlushAsync; Ignored write exception: {statusCode}");
asyncResult.FailSilently(); asyncResult.FailSilently();
} }
} }
@ -639,7 +639,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception e) catch (Exception e)
{ {
Logger.LogError(0, e, "SendFileAsync"); Logger.LogError(LoggerEventIds.FileSendAsyncError, e, "SendFileAsync");
asyncResult.Dispose(); asyncResult.Dispose();
Abort(); Abort();
throw; throw;
@ -649,21 +649,21 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
Logger.LogDebug($"SendFileAsync; Write cancelled with error code: {statusCode}"); Logger.LogDebug(LoggerEventIds.FileSendAsyncCancelled,$"SendFileAsync; Write cancelled with error code: {statusCode}");
asyncResult.Cancel(ThrowWriteExceptions); asyncResult.Cancel(ThrowWriteExceptions);
} }
else if (ThrowWriteExceptions) else if (ThrowWriteExceptions)
{ {
asyncResult.Dispose(); asyncResult.Dispose();
var exception = new IOException(string.Empty, new HttpSysException((int)statusCode)); var exception = new IOException(string.Empty, new HttpSysException((int)statusCode));
Logger.LogError(0, exception, "SendFileAsync"); Logger.LogError(LoggerEventIds.FileSendAsyncError, exception, "SendFileAsync");
Abort(); Abort();
throw exception; throw exception;
} }
else else
{ {
// Abort the request but do not close the stream, let future writes complete silently // Abort the request but do not close the stream, let future writes complete silently
Logger.LogDebug($"SendFileAsync; Ignored write exception: {statusCode}"); Logger.LogDebug(LoggerEventIds.FileSendAsyncErrorIgnored,$"SendFileAsync; Ignored write exception: {statusCode}");
asyncResult.FailSilently(); asyncResult.FailSilently();
} }
} }

View File

@ -233,18 +233,18 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{ {
if (asyncResult._cancellationToken.IsCancellationRequested) if (asyncResult._cancellationToken.IsCancellationRequested)
{ {
logger.LogDebug($"FlushAsync.IOCompleted; Write cancelled with error code: {errorCode}"); logger.LogDebug(LoggerEventIds.WriteCancelled,$"FlushAsync.IOCompleted; Write cancelled with error code: {errorCode}");
asyncResult.Cancel(asyncResult._responseStream.ThrowWriteExceptions); asyncResult.Cancel(asyncResult._responseStream.ThrowWriteExceptions);
} }
else if (asyncResult._responseStream.ThrowWriteExceptions) else if (asyncResult._responseStream.ThrowWriteExceptions)
{ {
var exception = new IOException(string.Empty, new HttpSysException((int)errorCode)); var exception = new IOException(string.Empty, new HttpSysException((int)errorCode));
logger.LogError(0, exception, "FlushAsync.IOCompleted"); logger.LogError(LoggerEventIds.WriteError, exception, "FlushAsync.IOCompleted");
asyncResult.Fail(exception); asyncResult.Fail(exception);
} }
else else
{ {
logger.LogDebug($"FlushAsync.IOCompleted; Ignored write exception: {errorCode}"); logger.LogDebug(LoggerEventIds.WriteErrorIgnored, $"FlushAsync.IOCompleted; Ignored write exception: {errorCode}");
asyncResult.FailSilently(); asyncResult.FailSilently();
} }
} }
@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
catch (Exception e) catch (Exception e)
{ {
logger.LogError(0, e, "FlushAsync.IOCompleted"); logger.LogError(LoggerEventIds.WriteError, e, "FlushAsync.IOCompleted");
asyncResult.Fail(e); asyncResult.Fail(e);
} }
} }