Skip to content

Move RequestContextOfT logging to separate class #31345

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
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
35 changes: 35 additions & 0 deletions src/Servers/HttpSys/src/RequestProcessing/RequestContextLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 static class RequestContextLog
{
private static readonly Action<ILogger, Exception?> _requestError =
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.RequestError, "ProcessRequestAsync");

private static readonly Action<ILogger, Exception?> _requestProcessError =
LoggerMessage.Define(LogLevel.Error, LoggerEventIds.RequestProcessError, "ProcessRequestAsync");

private static readonly Action<ILogger, Exception?> _requestsDrained =
LoggerMessage.Define(LogLevel.Information, LoggerEventIds.RequestsDrained, "All requests drained.");

public static void RequestError(ILogger logger, Exception exception)
{
_requestError(logger, exception);
}

public static void RequestProcessError(ILogger logger, Exception exception)
{
_requestProcessError(logger, exception);
}

public static void RequestsDrained(ILogger logger)
{
_requestsDrained(logger, null);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override async Task ExecuteAsync()
}
catch (Exception ex)
{
Log.RequestProcessError(Logger, ex);
RequestContextLog.RequestProcessError(Logger, ex);
if (context != null)
{
application.DisposeContext(context, ex);
Expand Down Expand Up @@ -85,14 +85,14 @@ protected override async Task ExecuteAsync()
{
if (messagePump.DecrementOutstandingRequest() == 0 && messagePump.Stopping)
{
Log.RequestsDrained(Logger);
RequestContextLog.RequestsDrained(Logger);
messagePump.SetShutdownSignal();
}
}
}
catch (Exception ex)
{
Log.RequestError(Logger, ex);
RequestContextLog.RequestError(Logger, ex);
Abort();
}
}
Expand Down