Skip to content

Commit 530a6ac

Browse files
author
R9 Fundamentals
committed
sample updates
1 parent f5699c8 commit 530a6ac

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

aspnetcore/fundamentals/http-logging/samples/8.x/HttpLoggingSample.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.Middleware" Version="9.3.0" />
11+
<PackageReference Include="Microsoft.Extensions.Compliance.Redaction" Version="9.3.0" />
12+
</ItemGroup>
13+
914
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.Extensions.Compliance.Classification;
2+
3+
namespace HttpLoggingSample
4+
{
5+
public static class MyTaxonomyClassifications
6+
{
7+
public static string Name => "MyTaxonomy";
8+
9+
public static DataClassification Private => new(Name, nameof(Private));
10+
public static DataClassification Public => new(Name, nameof(Public));
11+
public static DataClassification Personal => new(Name, nameof(Personal));
12+
}
13+
}

aspnetcore/fundamentals/http-logging/samples/8.x/Program.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define THIRD // FIRST SECOND THIRD
1+
#define THIRD // FIRST SECOND THIRD FORTH
22
#if NEVER
33
#elif FIRST
44
// <snippet_Addservices>
@@ -26,7 +26,7 @@
2626

2727
app.UseStaticFiles();
2828

29-
app.UseHttpLogging();
29+
app.UseHttpLogging();
3030

3131
app.Use(async (context, next) =>
3232
{
@@ -60,11 +60,54 @@
6060

6161
app.Run();
6262
// </snippet2>
63+
#elif FORTH
64+
using Microsoft.Extensions.Http.Diagnostics;
65+
using Microsoft.AspNetCore.Diagnostics.Logging;
66+
using Microsoft.Extensions.Compliance.Classification;
67+
using HttpLoggingSample;
68+
using Microsoft.Net.Http.Headers;
69+
70+
// <snippet_redactionOptions>
71+
var builder = WebApplication.CreateBuilder(args);
72+
73+
builder.Services.AddHttpLogging(o => { });
74+
builder.Services.AddRedaction();
75+
76+
builder.Services.AddHttpLoggingRedaction(op =>
77+
{
78+
op.RequestPathParameterRedactionMode = HttpRouteParameterRedactionMode.None;
79+
op.RequestPathLoggingMode = IncomingPathLoggingMode.Formatted;
80+
op.RequestHeadersDataClasses.Add(HeaderNames.Accept, MyTaxonomyClassifications.Public);
81+
op.ResponseHeadersDataClasses.Add(HeaderNames.ContentType, MyTaxonomyClassifications.Private);
82+
op.RouteParameterDataClasses = new Dictionary<string, DataClassification>
83+
{
84+
{ "one", MyTaxonomyClassifications.Personal },
85+
};
86+
// Add the paths that should be filtered, with a leading '/'.
87+
op.ExcludePathStartsWith.Add("/home");
88+
op.IncludeUnmatchedRoutes = true;
89+
});
90+
91+
var app = builder.Build();
92+
93+
app.UseHttpLogging();
94+
95+
if (!app.Environment.IsDevelopment())
96+
{
97+
app.UseExceptionHandler("/Error");
98+
}
99+
app.UseStaticFiles();
100+
101+
app.MapGet("/", () => "Logged!");
102+
app.MapGet("/home", () => "Not logged!");
103+
104+
app.Run();
105+
// </snippet_redactionOptions>
63106
#elif THIRD
64107
// <snippet3>
65108
using HttpLoggingSample;
66109
using Microsoft.AspNetCore.HttpLogging;
67-
110+
// <snippet6>
68111
// <snippet4>
69112
var builder = WebApplication.CreateBuilder(args);
70113

@@ -74,6 +117,9 @@
74117
});
75118
builder.Services.AddHttpLoggingInterceptor<SampleHttpLoggingInterceptor>();
76119
// </snippet4>
120+
builder.Services.AddRedaction();
121+
builder.Services.AddHttpLoggingRedaction(op => { });
122+
// </snippet6>
77123
var app = builder.Build();
78124

79125
if (!app.Environment.IsDevelopment())
@@ -83,7 +129,7 @@
83129

84130
app.UseStaticFiles();
85131

86-
app.UseHttpLogging();
132+
app.UseHttpLogging();
87133

88134
app.Use(async (context, next) =>
89135
{

0 commit comments

Comments
 (0)