-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds HttpLogging middleware (#31816)
* Adding logging * Progress * Logging * nit * Polishing HttpLogging * Namespace and nit * System * Fix public API * Feedback * Big perf wins for response body * Adds request body side * Another API pass * Combine request and response stream base type * Fixing variable * nit * Updating samples * Some feedback * Small fixups * API review feedback * Tests working and most of the feedback * rename * Feedback * bit more logging * More overloads * Fixing truncation * Update src/Middleware/HttpLogging/src/HttpRequestLog.cs Co-authored-by: Kahbazi <[email protected]> * More tests and log headers later * Test for invalid media type * Logging request body if it isn't logged * nit * Update src/Middleware/HttpLogging/src/HttpResponseLog.cs Co-authored-by: Kahbazi <[email protected]> * Feedback * Remove uneeded dep * Removing mroe * Abstractions? * Targeting pack and comments * Extra check * Fixing tests * Fixing tests * All of that feedback * Another round of feedback * Override writeasync * Feedback * Fixing some small parts * Fixing response buffering check Co-authored-by: Kahbazi <[email protected]>
- Loading branch information
Showing
35 changed files
with
2,773 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Middleware/HttpLogging/samples/HttpLogging.Sample/HttpLogging.Sample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" /> | ||
<Reference Include="Microsoft.AspNetCore.Routing" /> | ||
<Reference Include="Microsoft.AspNetCore" /> | ||
<Reference Include="Microsoft.Extensions.Logging.Console" /> | ||
<Reference Include="Microsoft.AspNetCore.HttpLogging" /> | ||
<Reference Include="Microsoft.Extensions.Hosting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
34 changes: 34 additions & 0 deletions
34
src/Middleware/HttpLogging/samples/HttpLogging.Sample/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace HttpLogging.Sample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureLogging(logging => | ||
{ | ||
// Json Logging | ||
logging.ClearProviders(); | ||
logging.AddJsonConsole(options => | ||
{ | ||
options.JsonWriterOptions = new JsonWriterOptions() | ||
{ | ||
Indented = true | ||
}; | ||
}); | ||
}) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Middleware/HttpLogging/samples/HttpLogging.Sample/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:63240", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"HttpLogging.Sample": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": "true", | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Middleware/HttpLogging/samples/HttpLogging.Sample/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.HttpLogging; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace HttpLogging.Sample | ||
{ | ||
public class Startup | ||
{ | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddHttpLogging(logging => | ||
{ | ||
logging.LoggingFields = HttpLoggingFields.All; | ||
}); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
app.UseHttpLogging(); | ||
app.UseRouting(); | ||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.Map("/", async context => | ||
{ | ||
context.Response.ContentType = "text/plain"; | ||
await context.Response.WriteAsync("Hello World!"); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Middleware/HttpLogging/samples/HttpLogging.Sample/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Middleware/HttpLogging/samples/HttpLogging.Sample/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
Oops, something went wrong.