Skip to content

Remove LogHelper in HttpSys #18030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Servers/HttpSys/src/HttpSysListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public HttpSysListener(HttpSysOptions options, ILoggerFactory loggerFactory)

Options = options;

Logger = LogHelper.CreateLogger(loggerFactory, typeof(HttpSysListener));
Logger = loggerFactory.CreateLogger<HttpSysListener>();

_state = State.Stopped;
_internalLock = new object();
Expand Down Expand Up @@ -92,7 +92,7 @@ public HttpSysListener(HttpSysOptions options, ILoggerFactory loggerFactory)
_requestQueue?.Dispose();
_urlGroup?.Dispose();
_serverSession?.Dispose();
LogHelper.LogException(Logger, ".Ctor", exception);
Logger.LogError(0, exception, ".Ctor");
throw;
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public void Start()
{
CheckDisposed();

LogHelper.LogTrace(Logger, "Starting the listener.");
Logger.LogTrace("Starting the listener.");

// 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
Expand Down Expand Up @@ -177,7 +177,7 @@ public void Start()
// Make sure the HttpListener instance can't be used if Start() failed.
_state = State.Disposed;
DisposeInternal();
LogHelper.LogException(Logger, "Start", exception);
Logger.LogError(0, exception, "Start");
throw;
}
}
Expand All @@ -195,7 +195,7 @@ private void Stop()
return;
}

LogHelper.LogTrace(Logger, "Stopping the listener.");
Logger.LogTrace("Stopping the listener.");

// If this instance created the queue then remove the URL prefixes before shutting down.
if (_requestQueue.Created)
Expand All @@ -210,7 +210,7 @@ private void Stop()
}
catch (Exception exception)
{
LogHelper.LogException(Logger, "Stop", exception);
Logger.LogError(0, exception, "Stop");
throw;
}
}
Expand Down Expand Up @@ -238,14 +238,14 @@ private void Dispose(bool disposing)
{
return;
}
LogHelper.LogTrace(Logger, "Disposing the listener.");
Logger.LogTrace("Disposing the listener.");

Stop();
DisposeInternal();
}
catch (Exception exception)
{
LogHelper.LogException(Logger, "Dispose", exception);
Logger.LogError(0, exception, "Dispose");
throw;
}
finally
Expand Down Expand Up @@ -300,7 +300,7 @@ public Task<RequestContext> AcceptAsync()
}
catch (Exception exception)
{
LogHelper.LogException(Logger, "GetContextAsync", exception);
Logger.LogError(0, exception, "GetContextAsync");
throw;
}

Expand Down
118 changes: 0 additions & 118 deletions src/Servers/HttpSys/src/LogHelper.cs

This file was deleted.

24 changes: 12 additions & 12 deletions src/Servers/HttpSys/src/MessagePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactor
}
_options = options.Value;
Listener = new HttpSysListener(_options, loggerFactory);
_logger = LogHelper.CreateLogger(loggerFactory, typeof(MessagePump));
_logger = loggerFactory.CreateLogger<MessagePump>();

if (_options.Authentication.Schemes != AuthenticationSchemes.None)
{
Expand Down Expand Up @@ -83,7 +83,7 @@ public Task StartAsync<TContext>(IHttpApplication<TContext> application, Cancell
{
if (_options.UrlPrefixes.Count > 0)
{
LogHelper.LogWarning(_logger, $"Overriding endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true." +
_logger.LogWarning($"Overriding endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true." +
$" Binding to address(es) '{string.Join(", ", _serverAddresses.Addresses)}' instead. ");

Listener.Options.UrlPrefixes.Clear();
Expand All @@ -95,7 +95,7 @@ public Task StartAsync<TContext>(IHttpApplication<TContext> application, Cancell
{
if (hostingUrlsPresent)
{
LogHelper.LogWarning(_logger, $"Overriding address(es) '{string.Join(", ", _serverAddresses.Addresses)}'. " +
_logger.LogWarning($"Overriding address(es) '{string.Join(", ", _serverAddresses.Addresses)}'. " +
$"Binding to endpoints added to {nameof(HttpSysOptions.UrlPrefixes)} instead.");

_serverAddresses.Addresses.Clear();
Expand All @@ -108,7 +108,7 @@ public Task StartAsync<TContext>(IHttpApplication<TContext> application, Cancell
}
else if (Listener.RequestQueue.Created)
{
LogHelper.LogDebug(_logger, $"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default.");
_logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default.");

Listener.Options.UrlPrefixes.Add(Constants.DefaultServerAddress);
}
Expand Down Expand Up @@ -171,11 +171,11 @@ private async void ProcessRequestsWorker()
Contract.Assert(Stopping);
if (Stopping)
{
LogHelper.LogDebug(_logger, "ListenForNextRequestAsync-Stopping", exception);
_logger.LogDebug(0, exception, "ListenForNextRequestAsync-Stopping");
}
else
{
LogHelper.LogException(_logger, "ListenForNextRequestAsync", exception);
_logger.LogError(0, exception, "ListenForNextRequestAsync");
}
continue;
}
Expand All @@ -187,7 +187,7 @@ private async void ProcessRequestsWorker()
{
// Request processing failed to be queued in threadpool
// Log the error message, release throttle and move on
LogHelper.LogException(_logger, "ProcessRequestAsync", ex);
_logger.LogError(0, ex, "ProcessRequestAsync");
}
}
Interlocked.Decrement(ref _acceptorCounts);
Expand Down Expand Up @@ -224,7 +224,7 @@ private async void ProcessRequestAsync(object requestContextObj)
}
catch (Exception ex)
{
LogHelper.LogException(_logger, "ProcessRequestAsync", ex);
_logger.LogError(0, ex, "ProcessRequestAsync");
_application.DisposeContext(context, ex);
if (requestContext.Response.HasStarted)
{
Expand All @@ -247,14 +247,14 @@ private async void ProcessRequestAsync(object requestContextObj)
{
if (Interlocked.Decrement(ref _outstandingRequests) == 0 && Stopping)
{
LogHelper.LogInfo(_logger, "All requests drained.");
_logger.LogInformation("All requests drained.");
_shutdownSignal.TrySetResult(0);
}
}
}
catch (Exception ex)
{
LogHelper.LogException(_logger, "ProcessRequestAsync", ex);
_logger.LogError(0, ex, "ProcessRequestAsync");
requestContext.Abort();
}
}
Expand All @@ -274,7 +274,7 @@ void RegisterCancelation()
{
if (Interlocked.Exchange(ref _shutdownSignalCompleted, 1) == 0)
{
LogHelper.LogInfo(_logger, "Canceled, terminating " + _outstandingRequests + " request(s).");
_logger.LogInformation("Canceled, terminating " + _outstandingRequests + " request(s).");
_shutdownSignal.TrySetResult(null);
}
});
Expand All @@ -292,7 +292,7 @@ void RegisterCancelation()
// Wait for active requests to drain
if (_outstandingRequests > 0)
{
LogHelper.LogInfo(_logger, "Stopping, waiting for " + _outstandingRequests + " request(s) to drain.");
_logger.LogInformation("Stopping, waiting for " + _outstandingRequests + " request(s) to drain.");
RegisterCancelation();
}
else
Expand Down
18 changes: 9 additions & 9 deletions src/Servers/HttpSys/src/NativeInterop/DisconnectListener.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,7 +34,7 @@ internal CancellationToken GetTokenForConnection(ulong connectionId)
}
catch (Win32Exception exception)
{
LogHelper.LogException(_logger, "GetConnectionToken", exception);
_logger.LogError(0, exception, "GetConnectionToken");
return CancellationToken.None;
}
}
Expand All @@ -54,12 +54,12 @@ private ConnectionCancellation GetCreatedConnectionCancellation(ulong connection
{
// Race condition on creation has no side effects
var cancellation = new ConnectionCancellation(this);
return _connectionCancellationTokens.GetOrAdd(connectionId, cancellation);
return _connectionCancellationTokens.GetOrAdd(connectionId, cancellation);
}

private unsafe CancellationToken CreateDisconnectToken(ulong connectionId)
{
LogHelper.LogDebug(_logger, "CreateDisconnectToken", "Registering connection for disconnect for connection ID: " + connectionId);
_logger.LogDebug("CreateDisconnectToken; Registering connection for disconnect for connection ID: " + connectionId);

// Create a nativeOverlapped callback so we can register for disconnect callback
var cts = new CancellationTokenSource();
Expand All @@ -70,8 +70,8 @@ private unsafe CancellationToken CreateDisconnectToken(ulong connectionId)
nativeOverlapped = new SafeNativeOverlapped(boundHandle, boundHandle.AllocateNativeOverlapped(
(errorCode, numBytes, overlappedPtr) =>
{
LogHelper.LogDebug(_logger, "CreateDisconnectToken", "http.sys disconnect callback fired for connection ID: " + connectionId);
_logger.LogDebug("CreateDisconnectToken; http.sys disconnect callback fired for connection ID: " + connectionId);

// Free the overlapped
nativeOverlapped.Dispose();

Expand All @@ -84,7 +84,7 @@ private unsafe CancellationToken CreateDisconnectToken(ulong connectionId)
}
catch (AggregateException exception)
{
LogHelper.LogException(_logger, "CreateDisconnectToken Callback", exception);
_logger.LogError(0, exception, "CreateDisconnectToken Callback");
}
},
null, null));
Expand All @@ -98,7 +98,7 @@ private unsafe CancellationToken CreateDisconnectToken(ulong connectionId)
catch (Win32Exception exception)
{
statusCode = (uint)exception.NativeErrorCode;
LogHelper.LogException(_logger, "CreateDisconnectToken", exception);
_logger.LogError(0, exception, "CreateDisconnectToken");
}

if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_IO_PENDING &&
Expand All @@ -108,7 +108,7 @@ private unsafe CancellationToken CreateDisconnectToken(ulong connectionId)
nativeOverlapped.Dispose();
ConnectionCancellation ignored;
_connectionCancellationTokens.TryRemove(connectionId, out ignored);
LogHelper.LogDebug(_logger, "HttpWaitForDisconnectEx", new Win32Exception((int)statusCode));
_logger.LogDebug(0, new Win32Exception((int)statusCode), "HttpWaitForDisconnectEx");
cts.Cancel();
}

Expand Down
Loading