RequestLogFeature doesn''t 404/403

Hey guys,

I noticed that RequestLogFeature doesn’t seem to log 404/403s (basically any error that happens before i’m actually in the request code). Error codes generated by the actual endpoint seem to be ok. is that something I can change?

I’m using AspnetAuthProvider, in case that is gumming up the works.

Yeah the request logger only logs requests that were executed by Services.

What’s the best way to catch these with regular logging then? Filters, or a custom httphandler?

The Request Logger was only meant for Service Requests but I’ve added support for other ServiceStack Requests in this commit which is available from v4.5.13 that’s now available on MyGet.

After short-circuited requests have closed the AppHost.OnEndRequest() will be called which you can override or register a AppHost.OnEndRequestCallbacks to register a delegate instead.

Please let me know if it adds the required logging.

The change does add the logging, thanks! (Didn’t need to register the delegate)

Would I use that delegate to cancel request logging of error codes I don’t care about (e.g. 302s)?

Also, it seems one consequence of this is that the short-circuited request log entry doesn’t seem to be tagged as a ErrorResponse in cases where it should be (403/404s).

I’ve added a SkipLogging predicate on RequestLogsFeature which you can use to skip ignoring requests you don’t care about, e.g. you can ignore all Redirect responses with:

Plugins.Add(new RequestLogsFeature
    SkipLogging = req => req.Response.StatusCode >= 300 && req.Response.StatusCode < 400,

This change is available from v4.5.13 which you can redownload from MyGet by clearing you NuGet cache.

The ErrorResponse is the serialized HTTP Response Body, most short-circuited requests don’t have a Response Body and the Logger doesn’t have access to the few that do as they’re written directly to the response Stream. HTTP Error Responses are determined when the Status Code >= 400.

1 Like

Thanks for the response as usual!

In InMemoryRollingRequestLogger.cs:

return ExcludeRequestType(requestType) && SkipLogging?.Invoke(req) == true;

Should that be || ?

Yep good catch, fixed in this commit, this fix is now available from v4.5.13 that’s now on MyGet.

Note: In future versions of ServiceStack, you will need to opt-in to log non Service Requests with:

Plugins.Add(new RequestLogsFeature {
    LimitToServiceRequests = false,
1 Like

Thanks for the heads up!