/
HttpLoggingFields.cs
202 lines (180 loc) · 7.59 KB
/
HttpLoggingFields.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.HttpLogging;
/// <summary>
/// Flags used to control which parts of the
/// request and response are logged.
/// </summary>
[Flags]
public enum HttpLoggingFields : long
{
/// <summary>
/// No logging.
/// </summary>
None = 0x0,
/// <summary>
/// Flag for logging the HTTP Request Path, which includes both the <see cref="HttpRequest.Path"/>
/// and <see cref="HttpRequest.PathBase"/>.
/// <para>
/// For example:
/// Path: /index
/// PathBase: /app
/// </para>
/// </summary>
RequestPath = 0x1,
/// <summary>
/// Flag for logging the HTTP Request <see cref="HttpRequest.QueryString"/>.
/// <para>
/// For example:
/// Query: ?index=1
/// </para>
/// RequestQuery contents can contain private information
/// which may have regulatory concerns under GDPR
/// and other laws. RequestQuery should not be logged
/// unless logs are secure and access controlled
/// and the privacy impact assessed.
/// </summary>
RequestQuery = 0x2,
/// <summary>
/// Flag for logging the HTTP Request <see cref="HttpRequest.Protocol"/>.
/// <para>
/// For example:
/// Protocol: HTTP/1.1
/// </para>
/// </summary>
RequestProtocol = 0x4,
/// <summary>
/// Flag for logging the HTTP Request <see cref="HttpRequest.Method"/>.
/// <para>
/// For example:
/// Method: GET
/// </para>
/// </summary>
RequestMethod = 0x8,
/// <summary>
/// Flag for logging the HTTP Request <see cref="HttpRequest.Scheme"/>.
/// <para>
/// For example:
/// Scheme: https
/// </para>
/// </summary>
RequestScheme = 0x10,
/// <summary>
/// Flag for logging the HTTP Response <see cref="HttpResponse.StatusCode"/>.
/// <para>
/// For example:
/// StatusCode: 200
/// </para>
/// </summary>
ResponseStatusCode = 0x20,
/// <summary>
/// Flag for logging the HTTP Request <see cref="HttpRequest.Headers"/>.
/// Request Headers are logged as soon as the middleware is invoked.
/// Headers are redacted by default with the character '[Redacted]' unless specified in
/// the <see cref="HttpLoggingOptions.RequestHeaders"/>.
/// <para>
/// For example:
/// Connection: keep-alive
/// My-Custom-Request-Header: [Redacted]
/// </para>
/// </summary>
RequestHeaders = 0x40,
/// <summary>
/// Flag for logging the HTTP Response <see cref="HttpResponse.Headers"/>.
/// Response Headers are logged when the <see cref="HttpResponse.Body"/> is written to
/// or when <see cref="IHttpResponseBodyFeature.StartAsync(System.Threading.CancellationToken)"/>
/// is called.
/// <para>
/// Headers are redacted by default with the character '[Redacted]' unless specified in
/// the <see cref="HttpLoggingOptions.ResponseHeaders"/>.
/// </para>
/// <para>
/// For example:
/// Content-Length: 16
/// My-Custom-Response-Header: [Redacted]
/// </para>
/// </summary>
ResponseHeaders = 0x80,
/// <summary>
/// Flag for logging the HTTP Request <see cref="IHttpRequestTrailersFeature.Trailers"/>.
/// Request Trailers are currently not logged.
/// </summary>
RequestTrailers = 0x100,
/// <summary>
/// Flag for logging the HTTP Response <see cref="IHttpResponseTrailersFeature.Trailers"/>.
/// Response Trailers are currently not logged.
/// </summary>
ResponseTrailers = 0x200,
/// <summary>
/// Flag for logging the HTTP Request <see cref="HttpRequest.Body"/>.
/// Logging the request body has performance implications, as it requires buffering
/// the entire request body up to <see cref="HttpLoggingOptions.RequestBodyLogLimit"/>.
/// </summary>
RequestBody = 0x400,
/// <summary>
/// Flag for logging the HTTP Response <see cref="HttpResponse.Body"/>.
/// Logging the response body has performance implications, as it requires buffering
/// the entire response body up to <see cref="HttpLoggingOptions.ResponseBodyLogLimit"/>.
/// </summary>
ResponseBody = 0x800,
/// <summary>
/// Flag for logging how long it took to process the request and response in milliseconds.
/// </summary>
Duration = 0x1000,
/// <summary>
/// Flag for logging a collection of HTTP Request properties,
/// including <see cref="RequestPath"/>, <see cref="RequestProtocol"/>,
/// <see cref="RequestMethod"/>, and <see cref="RequestScheme"/>.
/// </summary>
/// <remarks>
/// The HTTP Request <see cref="HttpRequest.QueryString"/> is not included with this flag as it may contain private information.
/// If desired, it should be explicitly specified with <see cref="RequestQuery"/>.
/// </remarks>
RequestProperties = RequestPath | RequestProtocol | RequestMethod | RequestScheme,
/// <summary>
/// Flag for logging HTTP Request properties and headers.
/// Includes <see cref="RequestProperties"/> and <see cref="RequestHeaders"/>
/// </summary>
/// <remarks>
/// The HTTP Request <see cref="HttpRequest.QueryString"/> is not included with this flag as it may contain private information.
/// If desired, it should be explicitly specified with <see cref="RequestQuery"/>.
/// </remarks>
RequestPropertiesAndHeaders = RequestProperties | RequestHeaders,
/// <summary>
/// Flag for logging HTTP Response properties and headers.
/// Includes <see cref="ResponseStatusCode"/> and <see cref="ResponseHeaders"/>.
/// </summary>
ResponsePropertiesAndHeaders = ResponseStatusCode | ResponseHeaders,
/// <summary>
/// Flag for logging the entire HTTP Request.
/// Includes <see cref="RequestPropertiesAndHeaders"/> and <see cref="RequestBody"/>.
/// Logging the request body has performance implications, as it requires buffering
/// the entire request body up to <see cref="HttpLoggingOptions.RequestBodyLogLimit"/>.
/// </summary>
/// <remarks>
/// The HTTP Request <see cref="HttpRequest.QueryString"/> is not included with this flag as it may contain private information.
/// If desired, it should be explicitly specified with <see cref="RequestQuery"/>.
/// </remarks>
Request = RequestPropertiesAndHeaders | RequestBody,
/// <summary>
/// Flag for logging the entire HTTP Response.
/// Includes <see cref="ResponsePropertiesAndHeaders"/> and <see cref="ResponseBody"/>.
/// Logging the response body has performance implications, as it requires buffering
/// the entire response body up to <see cref="HttpLoggingOptions.ResponseBodyLogLimit"/>.
/// </summary>
Response = ResponsePropertiesAndHeaders | ResponseBody,
/// <summary>
/// Flag for logging both the HTTP Request and Response.
/// Includes <see cref="Request"/>, <see cref="Response"/>, and <see cref="Duration"/>.
/// Logging the request and response body has performance implications, as it requires buffering
/// the entire request and response body up to the <see cref="HttpLoggingOptions.RequestBodyLogLimit"/>
/// and <see cref="HttpLoggingOptions.ResponseBodyLogLimit"/>.
/// </summary>
/// <remarks>
/// The HTTP Request <see cref="HttpRequest.QueryString"/> is not included with this flag as it may contain private information.
/// If desired, it should be explicitly specified with <see cref="RequestQuery"/>.
/// </remarks>
All = Request | Response | Duration
}