CsvRequestLogger not logging errors


I’m trying to configure csv request logging for error logging in a ServiceStack project, I got it set up and it’s logging requests to the csv file however it’s not logging errors, I’m doing a simple throw new Exception("test error"); in a service but the log just logs the request with StatusCode 200 and totally empty ResponseDto and error/exception cells.
The error log file is also not created.

I’m setting it up like so:

Plugins.Add(new RequestLogsFeature
    RequestLogger = new CsvRequestLogger(
        new FileSystemVirtualFiles(HostContext.Config.WebHostPhysicalPath),
    EnableResponseTracking = true,
    EnableRequestBodyTracking = true,
    EnableErrorTracking = true

I’ve tried throwing specific exceptions like ArgumentException too with no success.

ServiceStack is at V6.6

Any help would be appreciated.

Does your API have a Response DTO with a ResponseStatus property?

No our response DTOs do not have a ResponseStatus property.
I’ve just tried adding it to the response dto for the service in question and it doesn’t seem to have changed anything.

The request DTO looks like this:

public class CreateQuestionnaireMessage : IReturn<Message>
    public string To { get; set; }

    public string Subject { get; set; }

    public string Base64Body { get; set; }

    public int QuestionnaireMessageId { get; set; }

And the response:

public class Message
	public long Id { get; set; }

	public..(lots of other properties)
	public ResponseStatus ResponseStatus { get; set; }

The issue was due to the Error Response being converted into a Response DTO before it was logged in the Request Logger which should now be resolved from the latest v6.6.1+ that’s now available on MyGet and GitHub Packages.

Although the entry should still have been written to the main Request Logs, in addition errors are also written to the Error Log to make it easier to locate errors.

Thanks for the quick work!

The errors log file now gets created however the only errors in it are for authenticate requests returning 401 before login.

The error I’m throwing in the message service still isn’t caught and the request still just shows status 200 and no response/errors in the log, with and without ResponseStatus in the response dto.

Actually, my bad, it seems a try catch block was catching the error and preventing servicestack from handling it. The error is now showing in the errors log file.

Thanks again for your help.

1 Like