-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Adds HttpLogging middleware #31816
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
Adds HttpLogging middleware #31816
Changes from 37 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
08531c4
Adding logging
jkotalik b56367f
Progress
jkotalik cef0a0e
Logging
jkotalik 6c6f371
nit
jkotalik cb167a3
Polishing HttpLogging
jkotalik e3c2bb9
Namespace and nit
jkotalik a82072a
System
jkotalik 5b4d902
Fix public API
jkotalik 704059b
Feedback
jkotalik b43466f
Big perf wins for response body
jkotalik 1efe8b3
Adds request body side
jkotalik 1760864
Another API pass
jkotalik 28e2673
Combine request and response stream base type
jkotalik 472f1b5
Fixing variable
jkotalik 9ac7806
nit
jkotalik 8f75b8a
Updating samples
jkotalik 01efac0
Some feedback
jkotalik 47a2f0f
Small fixups
jkotalik c30c593
API review feedback
jkotalik 050f7c0
Tests working and most of the feedback
jkotalik 74ddd32
rename
jkotalik 5d55650
Feedback
jkotalik 1ad55fb
bit more logging
jkotalik 67e9222
More overloads
jkotalik 3497793
Fixing truncation
jkotalik 497c91b
Update src/Middleware/HttpLogging/src/HttpRequestLog.cs
jkotalik 6231ce3
More tests and log headers later
jkotalik a136458
Test for invalid media type
jkotalik 11023b8
Logging request body if it isn't logged
jkotalik 2f18049
nit
jkotalik 93f39b7
Update src/Middleware/HttpLogging/src/HttpResponseLog.cs
jkotalik ba81e51
Feedback
jkotalik ea63380
Remove uneeded dep
jkotalik 9327fc9
Removing mroe
jkotalik b9197c5
Abstractions?
jkotalik cb7fb4e
Targeting pack and comments
jkotalik c1b2d22
Extra check
jkotalik 0fe0424
Fixing tests
jkotalik 7b13787
Fixing tests
jkotalik e896579
All of that feedback
jkotalik b472d31
Another round of feedback
jkotalik 26d75f2
Override writeasync
jkotalik 8b3f610
Feedback
jkotalik 1073605
Fixing some small parts
jkotalik fc0073d
Fixing response buffering check
jkotalik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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> |
39 changes: 39 additions & 0 deletions
39
src/Middleware/HttpLogging/samples/HttpLogging.Sample/Program.cs
This file contains hidden or 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,39 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
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 hidden or 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" | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Middleware/HttpLogging/samples/HttpLogging.Sample/Startup.cs
This file contains hidden or 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,41 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.HttpLogging; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using System; | ||
jkotalik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.