CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Request logger
This page has moved to docs.servicestack.net/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());
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.
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.
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.
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.
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. |
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:
It supports multiple queryString filters and switches so you filter out related requests for better analysis and debuggability:
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.
- Why ServiceStack?
- Important role of DTOs
- What is a message based web service?
- Advantages of message based web services
- Why remote services should use separate DTOs
-
Getting Started
-
Designing APIs
-
Reference
-
Clients
-
Formats
-
View Engines 4. Razor & Markdown Razor
-
Hosts
-
Security
-
Advanced
- Configuration options
- Access HTTP specific features in services
- Logging
- Serialization/deserialization
- Request/response filters
- Filter attributes
- Concurrency Model
- Built-in profiling
- Form Hijacking Prevention
- Auto-Mapping
- HTTP Utils
- Dump Utils
- Virtual File System
- Config API
- Physical Project Structure
- Modularizing Services
- MVC Integration
- ServiceStack Integration
- Embedded Native Desktop Apps
- Auto Batched Requests
- Versioning
- Multitenancy
-
Caching
-
HTTP Caching 1. CacheResponse Attribute 2. Cache Aware Clients
-
Auto Query
-
AutoQuery Data 1. AutoQuery Memory 2. AutoQuery Service 3. AutoQuery DynamoDB
-
Server Events
-
Service Gateway
-
Encrypted Messaging
-
Plugins
-
Tests
-
ServiceStackVS
-
Other Languages
-
Amazon Web Services
-
Deployment
-
Install 3rd Party Products
-
Use Cases
-
Performance
-
Other Products
-
Future