Skip to content

Commit 00877b5

Browse files
committed
Create logger using string category
1 parent ff3cb76 commit 00877b5

28 files changed

+215
-40
lines changed

src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Microsoft.AspNetCore.Http;
66
using System.Threading.Tasks;
77
using Microsoft.AspNetCore.Routing;
88
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Logging;
910

1011
/// <summary>
1112
/// An <see cref="IResult"/> that on execution will write an object to the response
@@ -78,7 +79,11 @@ public Task ExecuteAsync(HttpContext httpContext)
7879
throw new InvalidOperationException("No route matches the supplied values.");
7980
}
8081

82+
// Creating the logger with a string to preserve the category after the refactoring.
83+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
84+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.AcceptedAtRouteResult");
85+
8186
httpContext.Response.Headers.Location = url;
82-
return HttpResultsHelper.WriteResultAsJsonAsync(httpContext, Value, StatusCode);
87+
return HttpResultsHelper.WriteResultAsJsonAsync(httpContext, logger, Value, StatusCode);
8388
}
8489
}

src/Http/Http.Results/src/AcceptedHttpResult.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace Microsoft.AspNetCore.Http;
55

66
using System.Threading.Tasks;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Logging;
79

810
/// <summary>
911
/// An <see cref="IResult"/> that on execution will write an object to the response
@@ -74,8 +76,12 @@ public Task ExecuteAsync(HttpContext httpContext)
7476
httpContext.Response.Headers.Location = Location;
7577
}
7678

79+
// Creating the logger with a string to preserve the category after the refactoring.
80+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
81+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.AcceptedResult");
7782
return HttpResultsHelper.WriteResultAsJsonAsync(
7883
httpContext,
84+
logger,
7985
Value,
8086
StatusCode);
8187
}

src/Http/Http.Results/src/BadRequestObjectHttpResult.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Microsoft.AspNetCore.Http;
55

6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
8+
69
/// <summary>
710
/// An <see cref="IResult"/> that on execution will write an object to the response
811
/// with Bad Request (400) status code.
@@ -32,5 +35,15 @@ internal BadRequestObjectHttpResult(object? error)
3235

3336
/// <inheritdoc/>
3437
public Task ExecuteAsync(HttpContext httpContext)
35-
=> HttpResultsHelper.WriteResultAsJsonAsync(httpContext, Value, StatusCode);
38+
{
39+
// Creating the logger with a string to preserve the category after the refactoring.
40+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
41+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.BadRequestObjectResult");
42+
43+
return HttpResultsHelper.WriteResultAsJsonAsync(
44+
httpContext,
45+
logger: logger,
46+
Value,
47+
StatusCode);
48+
}
3649
}

src/Http/Http.Results/src/ChallengeHttpResult.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ internal ChallengeHttpResult(IList<string> authenticationSchemes, Authentication
9090
/// <inheritdoc/>
9191
public async Task ExecuteAsync(HttpContext httpContext)
9292
{
93-
var logger = httpContext.RequestServices.GetRequiredService<ILogger<ChallengeHttpResult>>();
93+
// Creating the logger with a string to preserve the category after the refactoring.
94+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
95+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.ChallengeResult");
9496

9597
Log.ChallengeResultExecuting(logger, AuthenticationSchemes);
9698

src/Http/Http.Results/src/ConflictObjectHttpResult.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Microsoft.AspNetCore.Http;
55

6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
8+
69
/// <summary>
710
/// An <see cref="IResult"/> that on execution will write an object to the response
811
/// with Conflict (409) status code.
@@ -32,5 +35,15 @@ internal ConflictObjectHttpResult(object? error)
3235

3336
/// <inheritdoc/>
3437
public Task ExecuteAsync(HttpContext httpContext)
35-
=> HttpResultsHelper.WriteResultAsJsonAsync(httpContext, Value, StatusCode);
38+
{
39+
// Creating the logger with a string to preserve the category after the refactoring.
40+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
41+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.ConflictObjectResult");
42+
43+
return HttpResultsHelper.WriteResultAsJsonAsync(
44+
httpContext,
45+
logger: logger,
46+
Value,
47+
StatusCode);
48+
}
3649
}

src/Http/Http.Results/src/ContentHttpResult.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Microsoft.AspNetCore.Http;
55

6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
8+
69
/// <summary>
710
/// An <see cref="StatusCodeHttpResult"/> that when executed
811
/// will produce a response with content.
@@ -53,5 +56,11 @@ internal ContentHttpResult(string? content, string? contentType, int? statusCode
5356
/// <param name="httpContext">The <see cref="HttpContext"/> for the current request.</param>
5457
/// <returns>A task that represents the asynchronous execute operation.</returns>
5558
public Task ExecuteAsync(HttpContext httpContext)
56-
=> HttpResultsHelper.WriteResultAsContentAsync(httpContext, Content, StatusCode, ContentType);
59+
{
60+
// Creating the logger with a string to preserve the category after the refactoring.
61+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
62+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.ContentResult");
63+
64+
return HttpResultsHelper.WriteResultAsContentAsync(httpContext, logger, Content, StatusCode, ContentType);
65+
}
5766
}

src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Microsoft.AspNetCore.Http;
55

66
using Microsoft.AspNetCore.Routing;
77
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Logging;
89

910
/// <summary>
1011
/// An <see cref="IResult"/> that on execution will write an object to the response
@@ -77,9 +78,14 @@ public Task ExecuteAsync(HttpContext httpContext)
7778
throw new InvalidOperationException("No route matches the supplied values.");
7879
}
7980

81+
// Creating the logger with a string to preserve the category after the refactoring.
82+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
83+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.CreatedAtRouteResult");
84+
8085
httpContext.Response.Headers.Location = url;
8186
return HttpResultsHelper.WriteResultAsJsonAsync(
8287
httpContext,
88+
logger,
8389
Value,
8490
StatusCode);
8591
}

src/Http/Http.Results/src/CreatedHttpResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Microsoft.AspNetCore.Http;
55

6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
8+
69
/// <summary>
710
/// An <see cref="IResult"/> that on execution will write an object to the response
811
/// with status code Created (201) and Location header.
@@ -69,8 +72,12 @@ public Task ExecuteAsync(HttpContext httpContext)
6972
httpContext.Response.Headers.Location = Location;
7073
}
7174

75+
// Creating the logger with a string to preserve the category after the refactoring.
76+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
77+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.CreatedResult");
7278
return HttpResultsHelper.WriteResultAsJsonAsync(
7379
httpContext,
80+
logger,
7481
Value,
7582
StatusCode);
7683
}

src/Http/Http.Results/src/FileContentHttpResult.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.AspNetCore.Internal;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging;
57
using Microsoft.Net.Http.Headers;
68

79
namespace Microsoft.AspNetCore.Http;
@@ -102,14 +104,21 @@ internal FileContentHttpResult(
102104
public ReadOnlyMemory<byte> FileContents { get; internal init; }
103105

104106
/// <inheritdoc/>
105-
public Task ExecuteAsync(HttpContext httpContext) =>
106-
HttpResultsHelper.WriteResultAsFileAsync(
107+
public Task ExecuteAsync(HttpContext httpContext)
108+
{
109+
// Creating the logger with a string to preserve the category after the refactoring.
110+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
111+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.FileContentResult");
112+
113+
return HttpResultsHelper.WriteResultAsFileAsync(
107114
httpContext,
115+
logger,
108116
FileDownloadName,
109117
FileLength,
110118
ContentType,
111119
EnableRangeProcessing,
112120
LastModified,
113121
EntityTag,
114122
(context, range, rangeLength) => FileResultHelper.WriteFileAsync(httpContext, FileContents, range, rangeLength));
123+
}
115124
}

src/Http/Http.Results/src/FileStreamHttpResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.AspNetCore.Internal;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging;
57
using Microsoft.Net.Http.Headers;
68

79
namespace Microsoft.AspNetCore.Http;
@@ -113,10 +115,15 @@ internal FileStreamHttpResult(
113115
/// <inheritdoc/>
114116
public async Task ExecuteAsync(HttpContext httpContext)
115117
{
118+
// Creating the logger with a string to preserve the category after the refactoring.
119+
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
120+
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.FileStreamResult");
121+
116122
await using (FileStream)
117123
{
118124
await HttpResultsHelper.WriteResultAsFileAsync(
119125
httpContext,
126+
logger,
120127
FileDownloadName,
121128
FileLength,
122129
ContentType,

0 commit comments

Comments
 (0)