|
1 | | -#define THIRD // FIRST SECOND THIRD |
| 1 | +#define THIRD // FIRST SECOND THIRD FORTH |
2 | 2 | #if NEVER |
3 | 3 | #elif FIRST |
4 | 4 | // <snippet_Addservices> |
|
26 | 26 |
|
27 | 27 | app.UseStaticFiles(); |
28 | 28 |
|
29 | | -app.UseHttpLogging(); |
| 29 | +app.UseHttpLogging(); |
30 | 30 |
|
31 | 31 | app.Use(async (context, next) => |
32 | 32 | { |
|
60 | 60 |
|
61 | 61 | app.Run(); |
62 | 62 | // </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> |
63 | 106 | #elif THIRD |
64 | 107 | // <snippet3> |
65 | 108 | using HttpLoggingSample; |
66 | 109 | using Microsoft.AspNetCore.HttpLogging; |
67 | | - |
| 110 | +// <snippet6> |
68 | 111 | // <snippet4> |
69 | 112 | var builder = WebApplication.CreateBuilder(args); |
70 | 113 |
|
|
74 | 117 | }); |
75 | 118 | builder.Services.AddHttpLoggingInterceptor<SampleHttpLoggingInterceptor>(); |
76 | 119 | // </snippet4> |
| 120 | +builder.Services.AddRedaction(); |
| 121 | +builder.Services.AddHttpLoggingRedaction(op => { }); |
| 122 | +// </snippet6> |
77 | 123 | var app = builder.Build(); |
78 | 124 |
|
79 | 125 | if (!app.Environment.IsDevelopment()) |
|
83 | 129 |
|
84 | 130 | app.UseStaticFiles(); |
85 | 131 |
|
86 | | -app.UseHttpLogging(); |
| 132 | +app.UseHttpLogging(); |
87 | 133 |
|
88 | 134 | app.Use(async (context, next) => |
89 | 135 | { |
|
0 commit comments