Skip to content
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

Adds HttpLogging middleware #31816

Merged
merged 45 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
08531c4
Adding logging
jkotalik Apr 8, 2021
b56367f
Progress
jkotalik Apr 9, 2021
cef0a0e
Logging
jkotalik Apr 9, 2021
6c6f371
nit
jkotalik Apr 12, 2021
cb167a3
Polishing HttpLogging
jkotalik Apr 14, 2021
e3c2bb9
Namespace and nit
jkotalik Apr 14, 2021
a82072a
System
jkotalik Apr 14, 2021
5b4d902
Fix public API
jkotalik Apr 15, 2021
704059b
Feedback
jkotalik Apr 15, 2021
b43466f
Big perf wins for response body
jkotalik Apr 15, 2021
1efe8b3
Adds request body side
jkotalik Apr 16, 2021
1760864
Another API pass
jkotalik Apr 16, 2021
28e2673
Combine request and response stream base type
jkotalik Apr 16, 2021
472f1b5
Fixing variable
jkotalik Apr 16, 2021
9ac7806
nit
jkotalik Apr 16, 2021
8f75b8a
Updating samples
jkotalik Apr 16, 2021
01efac0
Some feedback
jkotalik Apr 16, 2021
47a2f0f
Small fixups
jkotalik Apr 16, 2021
c30c593
API review feedback
jkotalik Apr 16, 2021
050f7c0
Tests working and most of the feedback
jkotalik Apr 16, 2021
74ddd32
rename
jkotalik Apr 16, 2021
5d55650
Feedback
jkotalik Apr 16, 2021
1ad55fb
bit more logging
jkotalik Apr 16, 2021
67e9222
More overloads
jkotalik Apr 16, 2021
3497793
Fixing truncation
jkotalik Apr 16, 2021
497c91b
Update src/Middleware/HttpLogging/src/HttpRequestLog.cs
jkotalik Apr 19, 2021
6231ce3
More tests and log headers later
jkotalik Apr 19, 2021
a136458
Test for invalid media type
jkotalik Apr 19, 2021
11023b8
Logging request body if it isn't logged
jkotalik Apr 19, 2021
2f18049
nit
jkotalik Apr 19, 2021
93f39b7
Update src/Middleware/HttpLogging/src/HttpResponseLog.cs
jkotalik Apr 19, 2021
ba81e51
Feedback
jkotalik Apr 19, 2021
ea63380
Remove uneeded dep
jkotalik Apr 19, 2021
9327fc9
Removing mroe
jkotalik Apr 19, 2021
b9197c5
Abstractions?
jkotalik Apr 19, 2021
cb7fb4e
Targeting pack and comments
jkotalik Apr 19, 2021
c1b2d22
Extra check
jkotalik Apr 19, 2021
0fe0424
Fixing tests
jkotalik Apr 19, 2021
7b13787
Fixing tests
jkotalik Apr 19, 2021
e896579
All of that feedback
jkotalik Apr 20, 2021
b472d31
Another round of feedback
jkotalik Apr 20, 2021
26d75f2
Override writeasync
jkotalik Apr 20, 2021
8b3f610
Feedback
jkotalik Apr 20, 2021
1073605
Fixing some small parts
jkotalik Apr 20, 2021
fc0073d
Fixing response buffering check
jkotalik Apr 20, 2021
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
48 changes: 48 additions & 0 deletions AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.SpaSer
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalSample", "src\Http\samples\MinimalSample\MinimalSample.csproj", "{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpLogging", "HttpLogging", "{022B4B80-E813-4256-8034-11A68146F4EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.HttpLogging", "src\Middleware\HttpLogging\src\Microsoft.AspNetCore.HttpLogging.csproj", "{FF413F1C-A998-4FA2-823F-52AC0916B35C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.HttpLogging.Tests", "src\Middleware\HttpLogging\test\Microsoft.AspNetCore.HttpLogging.Tests.csproj", "{3A1EC883-EF9C-43E8-95E5-6B527428867B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpLogging.Sample", "src\Middleware\HttpLogging\samples\HttpLogging.Sample\HttpLogging.Sample.csproj", "{908B2263-B58B-4261-A125-B5F2DFF92799}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -7709,6 +7717,42 @@ Global
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}.Release|x64.Build.0 = Release|Any CPU
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}.Release|x86.ActiveCfg = Release|Any CPU
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}.Release|x86.Build.0 = Release|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|x64.ActiveCfg = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|x64.Build.0 = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|x86.ActiveCfg = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|x86.Build.0 = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Release|Any CPU.Build.0 = Release|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Release|x64.ActiveCfg = Release|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Release|x64.Build.0 = Release|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Release|x86.ActiveCfg = Release|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Release|x86.Build.0 = Release|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Debug|x64.ActiveCfg = Debug|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Debug|x64.Build.0 = Debug|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Debug|x86.ActiveCfg = Debug|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Debug|x86.Build.0 = Debug|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Release|Any CPU.Build.0 = Release|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Release|x64.ActiveCfg = Release|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Release|x64.Build.0 = Release|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Release|x86.ActiveCfg = Release|Any CPU
{3A1EC883-EF9C-43E8-95E5-6B527428867B}.Release|x86.Build.0 = Release|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Debug|Any CPU.Build.0 = Debug|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Debug|x64.ActiveCfg = Debug|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Debug|x64.Build.0 = Debug|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Debug|x86.ActiveCfg = Debug|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Debug|x86.Build.0 = Debug|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Release|Any CPU.ActiveCfg = Release|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Release|Any CPU.Build.0 = Release|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Release|x64.ActiveCfg = Release|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Release|x64.Build.0 = Release|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Release|x86.ActiveCfg = Release|Any CPU
{908B2263-B58B-4261-A125-B5F2DFF92799}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -8514,6 +8558,10 @@ Global
{DF4637DA-5F07-4903-8461-4E2DAB235F3C} = {7F99E967-3DC1-4198-9D55-47CD9471D0B6}
{AAB50C64-39AA-4AED-8E9C-50D68E7751AD} = {7F99E967-3DC1-4198-9D55-47CD9471D0B6}
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38} = {EB5E294B-9ED5-43BF-AFA9-1CD2327F3DC1}
{022B4B80-E813-4256-8034-11A68146F4EF} = {E5963C9F-20A6-4385-B364-814D2581FADF}
{FF413F1C-A998-4FA2-823F-52AC0916B35C} = {022B4B80-E813-4256-8034-11A68146F4EF}
{3A1EC883-EF9C-43E8-95E5-6B527428867B} = {022B4B80-E813-4256-8034-11A68146F4EF}
{908B2263-B58B-4261-A125-B5F2DFF92799} = {022B4B80-E813-4256-8034-11A68146F4EF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}
Expand Down
1 change: 1 addition & 0 deletions eng/ProjectReferences.props
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<ProjectReferenceProvider Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" ProjectPath="$(RepoRoot)src\Middleware\HealthChecks.EntityFrameworkCore\src\Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" ProjectPath="$(RepoRoot)src\Middleware\HealthChecks\src\Microsoft.AspNetCore.Diagnostics.HealthChecks.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HostFiltering" ProjectPath="$(RepoRoot)src\Middleware\HostFiltering\src\Microsoft.AspNetCore.HostFiltering.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HttpLogging" ProjectPath="$(RepoRoot)src\Middleware\HttpLogging\src\Microsoft.AspNetCore.HttpLogging.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HttpOverrides" ProjectPath="$(RepoRoot)src\Middleware\HttpOverrides\src\Microsoft.AspNetCore.HttpOverrides.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HttpsPolicy" ProjectPath="$(RepoRoot)src\Middleware\HttpsPolicy\src\Microsoft.AspNetCore.HttpsPolicy.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Localization.Routing" ProjectPath="$(RepoRoot)src\Middleware\Localization.Routing\src\Microsoft.AspNetCore.Localization.Routing.csproj" />
Expand Down
1 change: 1 addition & 0 deletions eng/SharedFramework.Local.props
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Diagnostics" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.HostFiltering" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.HttpLogging" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.HttpOverrides" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.HttpsPolicy" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Localization.Routing" />
Expand Down
2 changes: 2 additions & 0 deletions src/Framework/test/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static TestData()
"Microsoft.AspNetCore.Http.Connections.Common",
"Microsoft.AspNetCore.Http.Extensions",
"Microsoft.AspNetCore.Http.Features",
"Microsoft.AspNetCore.HttpLogging",
"Microsoft.AspNetCore.HttpOverrides",
"Microsoft.AspNetCore.HttpsPolicy",
"Microsoft.AspNetCore.Identity",
Expand Down Expand Up @@ -186,6 +187,7 @@ static TestData()
{ "Microsoft.AspNetCore.Http.Connections.Common", "6.0.0.0" },
{ "Microsoft.AspNetCore.Http.Extensions", "6.0.0.0" },
{ "Microsoft.AspNetCore.Http.Features", "6.0.0.0" },
{ "Microsoft.AspNetCore.HttpLogging", "6.0.0.0" },
{ "Microsoft.AspNetCore.HttpOverrides", "6.0.0.0" },
{ "Microsoft.AspNetCore.HttpsPolicy", "6.0.0.0" },
{ "Microsoft.AspNetCore.Identity", "6.0.0.0" },
Expand Down
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 src/Middleware/HttpLogging/samples/HttpLogging.Sample/Program.cs
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>();
});
}
}
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 src/Middleware/HttpLogging/samples/HttpLogging.Sample/Startup.cs
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.ConfigureHttpLogging(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!");
});
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
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": "*"
}
Loading