/servicestack-seq-requestlogsfeature

Servicestack plugin that logs requests to seq

Primary LanguageC#Mozilla Public License 2.0MPL-2.0

ServiceStack.Seq.RequestLogsFeature

Build status NuGet version

A ServiceStack plugin that logs requests to Seq. For more details view the blog post

NB. This version is compatible with ServiceStack v5.x. For v3 compatibility, use the v3 branch

Installing

The package is available from nuget.org

Install-Package ServiceStack.Seq.RequestLogsFeature

Requirements

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

Quick Start

In your AppHost class Configure method, add the plugin. By default configuration values are read from the registered IAppSettings instance. By default this will be an instance of AppSettings, if an alternative implementation of IAppSettings is to be used it must be registered prior to this plugin being registered. Alternatively all configuration options are exposed as public properties of the feature class.

public override void Configure(Container container)
{
    // Basic setup. All config read from AppSettings
    Plugins.Add(new SeqRequestLogsFeature());

	// Register plugin, setting optional properties 
    Plugins.Add(new SeqRequestLogsFeature
    {
        // add additional properties to Seq log entry.
        AppendProperties = (request, dto, response, duration) => new Dictionary<string, object> { { "NewCustomProperty", "42" } },

        // exclude specific dto types from logging
        ExcludeRequestDtoTypes = new[] { typeof(SeqRequestLogConfig) }, 
        
        // exclude request body logging for specific dto types
        HideRequestBodyForRequestDtoTypes = new[] { typeof(SeqRequestLogConfig) },
        
        // custom request logging exclusion
        SkipLogging = (request) => request.RawUrl == "/ignoreme"; 
    });
}

Configuration Options

Property Description AppSettings key
SeqUrl URI of Seq server. Required servicestack.seq.requestlogs.seq.url
ApiKey Seq Api Key servicestack.seq.requestlogs.seq.apikey
Enabled Default True servicestack.seq.requestlogs.enabled
EnableErrorTracking Default True servicestack.seq.requestlogs.errortracking.enabled
EnableRequestBodyTracking Default False servicestack.seq.requestlogs.requestbodytracking.enabled
EnableSessionTracking Default False servicestack.seq.requestlogs.sessiontracking.enabled
EnableResponseTracking Default False servicestack.seq.requestlogs.responsetracking.enabled
AppendProperties Add additional properties to log N/A
RawEventLogger low evel delegate for custom logging, bypasses all other settings responsetracking.enabled
Logger Swap out seq logger for custom implementation responsetracking.enabled
RequiredRoles Restrict the runtime configuration to specific roles servicestack.seq.requestlogs.requiredroles
HideRequestBodyForRequestDtoTypes Type exclusions for body request logging N/A
ExcludeRequestDtoTypes Type exclusions for logging N/A
SkipLogging Skip logging for any custom IRequest conditions N/A

Request Correlation

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

Runtime configuration

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);

Metadata page

Metadata

Logging in action

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

Seq Request Logs