-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
The property value exceeds the maximum allowed size (64KB). If the property value is a string, it is UTF-16 encoded and the maximum number of characters should be 32K or less. #722
Comments
Consider that with your current configuration, the middleware will log all requests, including those that do not reach an action method (e.g., unresolved routes or parsing errors). Additionally, it logs all request headers, response headers, and the response body. You can probably optimize your middleware configuration by applying more filtering and using an app.UseAuditMiddleware(_ => _
.FilterByRequest(r =>
!r.Method.Equals(nameof(HttpMethod.Get), StringComparison.OrdinalIgnoreCase)
&& r.Path.StartsWithSegments("/api"))
.WithEventType("{verb}:{url}")
.IncludeHeaders()
.IncludeResponseHeaders()
.IncludeResponseBody());
// Add a custom action to process and trim large audit data
Audit.Core.Configuration.AddCustomAction(ActionType.OnEventSaving, scope =>
{
var action = scope.GetWebApiAuditAction();
// Truncate excessively large headers
foreach (var headerKey in action.Headers.Keys)
{
if (action.Headers[headerKey]?.Length > 1024)
{
action.Headers[headerKey] = "too long...";
}
}
// Truncate excessively large response headers
foreach (var headerKey in action.ResponseHeaders.Keys)
{
if (action.ResponseHeaders[headerKey]?.Length > 1024)
{
action.ResponseHeaders[headerKey] = "too long...";
}
}
// Truncate excessively large response bodies
// NOTE: The action.ResponseBody.Length is derived from the Content-Length response header. If the server does not send this header, it will be null.
if (action.ResponseBody is { Value: not null, Length: > 16384 })
{
action.ResponseBody.Value = "too long...";
}
}); You might also consider setting up a fallback mechanism to log failed audit events in an alternative location for debugging purposes. One approach is to use the using Audit.AzureStorageTables.Providers;
using Audit.Polly;
using Audit.Core.Providers;
var azureTableStorage = new AzureTableDataProvider(config => config
.Endpoint(new Uri("..."))
.TableName(evt => "...")
.ClientOptions(...)
.EntityBuilder(...));
var fallbackStorage = new DynamicDataProvider(config => config
.OnInsert(auditEvent =>
{
Console.WriteLine(auditEvent.ToJson());
}));
// var fallbackStorage = new FileDataProvider(config => config.Directory(@"C:\Logs"));
Audit.Core.Configuration.Setup()
.JsonSystemAdapter(options)
.UsePolly(polly => polly
.DataProvider(azureTableStorage)
.WithResilience(resilience => resilience
.AddFallback(new()
{
ShouldHandle = new PredicateBuilder().Handle<Exception>(),
FallbackAction = args => args.FallbackToDataProvider(fallbackStorage)
}))); Key Points:
|
Thanks @thepirat000 for your response. I implemented the code changes suggested by you but still getting the error. One observation I see the custom action method : AddCustomAction is not getting triggered in this case Here are the options that I tried Option 1 :
Option 2:
Any help on this issue is much appreciated |
Is your other custom action If it is, then you might not be reaching the line where Or maybe the request was just filtered out by your configuration |
Thanks much @thepirat000 for your response. The below configuration worked out for me. But still I wanted to get confirmation from you from implementation point of view about its validity. Also I wanted to know what exactly the values 16384 point to you. My assumption is bytes. From the error : maximum number of characters should be 32K or less , hence in that case the condition needs to be modified accordingly ?. Also can you please help me to know how to handle any error occurs. In short assuming an error occured during action method execution, in that case I want to handle the error with some logging and let allow the method to complete its execution. Right now with the current implementation in case any error occurs while the action method is executed it completely blocks the method execution. Any help on this request is much appreciated.
|
Your approach looks good to me. As for The audit middleware will log the request (unless filtered out), even if the action method throws an exception. I suspect that something else is occurring after the exception is thrown; otherwise, you should see the exception details in the .Columns(col => col
.FromDictionary(auditEvent => new Dictionary<string, object>()
{
{ "Exception", auditEvent.GetWebApiAuditAction().Exception },
... |
Thanks @thepirat000 for your response. The current Audittrail implementation works almost 90% cases in lower environment. I tested it through in DEV and QA. Once it is PRODUCTION I see where the data content produced as part of API response is more it fails with the error : The property value exceeds the maximum allowed size (64KB). If the property value is a string, it is UTF-16 encoded and the maximum number of characters should be 32K or less.. Now in this case I wanted to know is it possible to handle the error by just logging the exception and let allow the Web API method to execute successfully without any issues. |
To ensure the Web API method executes successfully even if audit saving fails, you can use var azureTableDataProvider = new AzureTableDataProvider(config => config
.Endpoint(new Uri("..."))
.TableName(evt => "...")
.ClientOptions(...)
.EntityBuilder(...));
var fallbackDataProvider = new DynamicDataProvider(c => c.OnInsert(auditEvent =>
{
Console.WriteLine(auditEvent.ToJson());
}));
Audit.Core.Configuration.Setup()
.UsePolly(polly => polly
.DataProvider(azureTableDataProvider)
.WithResilience(resilience => resilience
.AddFallback(new()
{
ShouldHandle = new PredicateBuilder().Handle<Exception>(),
FallbackAction = args => args.FallbackToDataProvider(fallbackDataProvider)
}))); |
Thanks @thepirat000 for your response. Finally it got resolved :). Thanks a ton once again for your help and support on this request. |
Hi Daniel,
Thanks a lot for sharing with us a great library which has a very good documentation also : https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.WebApi/README.md for implementation of Audit Trail.
I need your help for a scenario detailed at : https://stackoverflow.com/questions/79362056/property-value-exceeds-the-maximum-allowed-size-64kb-if-the-property-value-is
Any help on this request is much appreciated
Thanks,
Santosh
The text was updated successfully, but these errors were encountered: