Skip to content

Commit fa13f8b

Browse files
committed
chore: create seperate named log methods
TODO: Should be checked, we still need the full methods when using the attribute LoggerMessage. Maybe we can delete the non attribute using method then?
1 parent 0299184 commit fa13f8b

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationHandler.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4747
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
4848
if (!response.IsSuccessStatusCode)
4949
{
50-
await Log.UserProfileErrorAsync(Logger, response, Context.RequestAborted);
50+
await Log.BasicUserInfoErrorAsync(Logger, response, Context.RequestAborted);
5151
throw new HttpRequestException("An error occurred while retrieving basic user information from Etsy.");
5252
}
5353

@@ -117,7 +117,7 @@ protected virtual async Task<JsonDocument> GetDetailedUserInfoAsync([NotNull] OA
117117
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
118118
if (!response.IsSuccessStatusCode)
119119
{
120-
await Log.UserProfileErrorAsync(Logger, response, Context.RequestAborted);
120+
await Log.DetailedUserInfoErrorAsync(Logger, response, Context.RequestAborted);
121121
throw new HttpRequestException("An error occurred while retrieving detailed user info from Etsy.");
122122
}
123123

@@ -126,18 +126,38 @@ protected virtual async Task<JsonDocument> GetDetailedUserInfoAsync([NotNull] OA
126126

127127
private static partial class Log
128128
{
129-
internal static async Task UserProfileErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
129+
internal static async Task BasicUserInfoErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
130130
{
131-
UserProfileError(
131+
BasicUserInfoError(
132132
logger,
133+
response.RequestMessage?.RequestUri?.ToString() ?? string.Empty,
133134
response.StatusCode,
134135
response.Headers.ToString(),
135136
await response.Content.ReadAsStringAsync(cancellationToken));
136137
}
137138

138-
[LoggerMessage(1, LogLevel.Error, "An error occurred while retrieving the user profile from Etsy: the remote server returned a {Status} response with the following payload: {Headers} {Body}.")]
139-
private static partial void UserProfileError(
139+
internal static async Task DetailedUserInfoErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
140+
{
141+
DetailedUserInfoError(
142+
logger,
143+
response.RequestMessage?.RequestUri?.ToString() ?? string.Empty,
144+
response.StatusCode,
145+
response.Headers.ToString(),
146+
await response.Content.ReadAsStringAsync(cancellationToken));
147+
}
148+
149+
[LoggerMessage(1, LogLevel.Error, "Etsy basic user info request failed for '{RequestUri}': remote server returned a {Status} response with: {Headers} {Body}.")]
150+
private static partial void BasicUserInfoError(
151+
ILogger logger,
152+
string requestUri,
153+
System.Net.HttpStatusCode status,
154+
string headers,
155+
string body);
156+
157+
[LoggerMessage(2, LogLevel.Error, "Etsy detailed user info request failed for '{RequestUri}': remote server returned a {Status} response with: {Headers} {Body}.")]
158+
private static partial void DetailedUserInfoError(
140159
ILogger logger,
160+
string requestUri,
141161
System.Net.HttpStatusCode status,
142162
string headers,
143163
string body);

0 commit comments

Comments
 (0)