A ServiceStack plugin that logs requests to Seq. For more details view the blog post
NB. This version is compatible with ServiceStack v4.x. For v3 compatibility, use the v3 branch
The package is available from nuget.org
Install-Package ServiceStack.Seq.RequestLogsFeature
You must have an instance of seq server to post to. You can download and install a copy of Seq here.
Out of the box, Seq includes a free single-user license without authentication support.
Once you have it installed, you can check it is running locally on the default port http://localhost:5341
In your AppHost
class Configure
method, add the plugin and specify your seq url.
You can futher customise the configuration options using the example below
public override void Configure(Container container)
{
// Config examples
Plugins.Add(
new SeqRequestLogsFeature(
new SeqRequestLogsSettings("http://localhost:5341") // required seq server url:port
// everything else is optional
.ApiKey("seqApiKey") // api key for seq
.Enabled() // default true
.EnableErrorTracking() // default true
.EnableSessionTracking() // default false
.EnableRequestBodyTracking() // default false
.EnableResponseTracking() // default false
.ExcludeRequestDtoTypes(typeof(SeqRequestLogConfig)) // add your own type exclusions
.HideRequestBodyForRequestDtoTypes(typeof(SeqRequestLogConfig)) // add your own exclusions for bodyrequest logging
.RequiredRoles("admin", "ops") // restrict the runtime configuration to specific roles
.UseCustomLogger(new CustomLogger()) // swap out the seq logger for your own implementation
.ClearExcludeRequestDtoTypes() // remove default exclusions (RequestLog)
.ClearHideRequestBodyForRequestDtoTypes() // remove default request body exclusions (Auth, Registration)
.AppendProperties(
(request, dto, response, duration) =>
{
return new Dictionary<string, object>() { { "NewCustomProperty", "42" } }; //add additional properties to Seq log entry.
})
.AddLogEvent(
(request, dto, response, duration) =>
{
// your custom log event
})));
}
This plugin will detect the default header x-mac-requestid
created by ServiceStack.Request.Correlation
and add this as a property. This is useful for tracking requests from their point of origin across multiple services
You can change the logging configuration at runtime
var request = new SeqRequestLogConfig
{
Enabled = false,
EnableRequestBodyTracking = false,
EnableErrorTracking = false,
EnableSessionTracking = false,
EnableResponseTracking = false
};
var client = new JsonServiceClient("http://myservice");
client.Send(request);
Once you start your AppHost
, every request will be now logged to seq using the default options or the options you provided.
Logging levels are colour coded and depending on your settings, the full requestDto's and even responseDto's are available to search.
In the example below you can see just a few examples of how the log data can be manipulated. For more info on the power of seq and structured logging, see the docs