Edit on GitHub

Request Logger

Add an In-Memory IRequestLogger and service with the default route at /requestlogs which maintains a live log of the most recent requests (and their responses). Supports multiple config options incl. Rolling-size capacity, error and session tracking, hidden request bodies for sensitive services, etc.

Plugins.Add(new RequestLogsFeature());

CSV Request Logger

One of the areas where ServiceStack’s CSV Support shines is being able to store daily Request Logs in a plain-text structured format, that way they could be immediately inspectable with a text editor or for even better inspection, opened in a spreadsheet and benefit from its filterable, movable, resizable and sortable columns.

To enable CSV Request Logging you just need to register the RequestLogsFeature and configure it to use the CsvRequestLogger:

Plugins.Add(new RequestLogsFeature {
    RequestLogger = new CsvRequestLogger(),
});

This will register the CSV Request logger with the following overridable defaults:

Plugins.Add(new RequestLogsFeature {
    RequestLogger = new CsvRequestLogger(
        files: new FileSystemVirtualPathProvider(this, Config.WebHostPhysicalPath),
        requestLogsPattern: "requestlogs/{year}-{month}/{year}-{month}-{day}.csv",
        errorLogsPattern: "requestlogs/{year}-{month}/{year}-{month}-{day}-errors.csv",
        appendEvery: TimeSpan.FromSeconds(1)
    ),
});

Where Request Logs are flushed every 1 second using a background Timer to a daily log maintained in the logical date format structure above. As it would be useful to be able to inspect any errors in isolation, errors are also written to a separate YYYY-MM-DD-errors.csv format, in addition to the main Request logs.

Custom CSV AutoQuery Data implementation

The AutoQuery Service example shows you can quickly create an AutoQuery Data Service that lets you inspect your CSV Request and Error Logs with AutoQuery, which in addition to the rich querying benefits also gives you access to an instant UI in AutoQuery Viewer to be able to View your Request Logs.

Redis Request Logger

The HTTP Request logs can also be configured to persist to a distributed Redis data store instead by configuring the RequestLogsFeature plugin to use the RedisRequestLogger. Persisting logs in redis will allow them to survive and be view-able across App Domain restarts.

Install

To use RedisRequestLogger first install the ServiceStack.Server NuGet package:

PM> Install-Package ServiceStack.Server

Then configure RequestLogsFeature to use the RedisRequestLogger which can make use of your existing IRedisClientsManager registered IOC dependency, e.g:

Plugins.Add(new RequestLogsFeature {
    RequestLogger = new RedisRequestLogger(
	    container.Resolve<IRedisClientsManager>(), capacity:1000)
});

The optional capacity configures the Redis Request Logger to work as a rolling log where it will only keep the most recent 1000 entries.

Configuration

Like other ServiceStack Plugins the RequestLogsFeature has a number of configuration options that can be specified at registration to customize Request Logging:

Name Type Description
AtRestPath string RequestLogs service Route, default is `/requestlogs`
EnableSessionTracking bool Turn On/Off Session Tracking
EnableRequestBodyTracking bool Turn On/Off Logging of Raw Request Body, default is Off
EnableResponseTracking bool Turn On/Off Tracking of Responses
EnableErrorTracking bool Turn On/Off Tracking of Exceptions
Capacity int? Size of InMemoryRollingRequestLogger circular buffer
RequiredRoles string[] Limit access to /requestlogs service to these roles
RequestLogger IRequest Logger Change the RequestLogger provider. Default is InMemoryRollingRequestLogger
ExcludeRequestDtoTypes Type[] Don't log requests of these types. By default RequestLog's are excluded
HideRequestBody ForRequestDtoTypes Type[] Don't log request bodys for services with sensitive information. By default Auth and Registration requests are hidden.

Usage

The IRequestLogger is a great way to introspect and analyze your service requests in real-time. Here’s a screenshot from the bootstrapapi.servicestack.net website:

Live Screenshot

It supports multiple queryString filters and switches so you filter out related requests for better analysis and debuggability:

Request Logs Usage

The RequestLogsService is just a simple C# service under-the-hood but is a good example of how a little bit of code can provide a lot of value in ServiceStack’s by leveraging its generic, built-in features.