|
|
@@ -13,32 +13,73 @@ public sealed class HttpLoggingAttribute : Attribute
|
|
|
/// Initializes an instance of the <see cref="HttpLoggingAttribute"/> class.
|
|
|
/// </summary>
|
|
|
/// <param name="loggingFields">Specifies what fields to log for the endpoint.</param>
|
|
|
- /// <param name="requestBodyLogLimit">Specifies the maximum number of bytes to be logged for the request body. A value of <c>-1</c> means use the default setting in <see cref="HttpLoggingOptions.RequestBodyLogLimit"/>.</param>
|
|
|
- /// <param name="responseBodyLogLimit">Specifies the maximum number of bytes to be logged for the response body. A value of <c>-1</c> means use the default setting in <see cref="HttpLoggingOptions.ResponseBodyLogLimit"/>.</param>
|
|
|
- /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="requestBodyLogLimit"/> or <paramref name="responseBodyLogLimit"/> is less than <c>-1</c>.</exception>
|
|
|
- public HttpLoggingAttribute(HttpLoggingFields loggingFields, int requestBodyLogLimit = -1, int responseBodyLogLimit = -1)
|
|
|
+ public HttpLoggingAttribute(HttpLoggingFields loggingFields)
|
|
|
{
|
|
|
LoggingFields = loggingFields;
|
|
|
-
|
|
|
- ArgumentOutOfRangeException.ThrowIfLessThan(requestBodyLogLimit, -1);
|
|
|
- ArgumentOutOfRangeException.ThrowIfLessThan(responseBodyLogLimit, -1);
|
|
|
-
|
|
|
- RequestBodyLogLimit = requestBodyLogLimit;
|
|
|
- ResponseBodyLogLimit = responseBodyLogLimit;
|
|
|
}
|
|
|
|
|
|
+ private int _responseBodyLogLimit;
|
|
|
+ private int _requestBodyLogLimit;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Specifies what fields to log.
|
|
|
/// </summary>
|
|
|
public HttpLoggingFields LoggingFields { get; }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Indicates whether <see cref="RequestBodyLogLimit"/> has been set.
|
|
|
+ /// </summary>
|
|
|
+ public bool IsRequestBodyLogLimitSet { get; private set; }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Specifies the maximum number of bytes to be logged for the request body.
|
|
|
/// </summary>
|
|
|
- public int RequestBodyLogLimit { get; }
|
|
|
+ /// <exception cref="ArgumentOutOfRangeException">Thrown when <see cref="RequestBodyLogLimit"/> set to a value less than <c>0</c>.</exception>
|
|
|
+ /// <exception cref="InvalidOperationException">Thrown when getting <see cref="RequestBodyLogLimit"/> if it hasn't been set to a value. Check <see cref="IsRequestBodyLogLimitSet"/> first.</exception>
|
|
|
+ public int RequestBodyLogLimit
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ if (IsRequestBodyLogLimitSet)
|
|
|
+ {
|
|
|
+ return _requestBodyLogLimit;
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new InvalidOperationException($"{nameof(RequestBodyLogLimit)} was not set. Check {nameof(IsRequestBodyLogLimitSet)} before accessing this property.");
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ ArgumentOutOfRangeException.ThrowIfLessThan(value, 0, nameof(RequestBodyLogLimit));
|
|
|
+ _requestBodyLogLimit = value;
|
|
|
+ IsRequestBodyLogLimitSet = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Indicates whether <see cref="ResponseBodyLogLimit"/> has been set.
|
|
|
+ /// </summary>
|
|
|
+ public bool IsResponseBodyLogLimitSet { get; private set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Specifies the maximum number of bytes to be logged for the response body.
|
|
|
/// </summary>
|
|
|
- public int ResponseBodyLogLimit { get; }
|
|
|
+ /// <exception cref="ArgumentOutOfRangeException">Thrown when <see cref="ResponseBodyLogLimit"/> set to a value less than <c>0</c>.</exception>
|
|
|
+ /// <exception cref="InvalidOperationException">Thrown when getting <see cref="ResponseBodyLogLimit"/> if it hasn't been set to a value. Check <see cref="IsResponseBodyLogLimitSet"/> first.</exception>
|
|
|
+ public int ResponseBodyLogLimit
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ if (IsResponseBodyLogLimitSet)
|
|
|
+ {
|
|
|
+ return _responseBodyLogLimit;
|
|
|
+ }
|
|
|
+ throw new InvalidOperationException($"{nameof(ResponseBodyLogLimit)} was not set. Check {nameof(IsResponseBodyLogLimitSet)} before accessing this property.");
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ ArgumentOutOfRangeException.ThrowIfLessThan(value, 0, nameof(ResponseBodyLogLimit));
|
|
|
+ _responseBodyLogLimit = value;
|
|
|
+ IsResponseBodyLogLimitSet = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|