Skip to content

dandcg/servicestack-seq-requestlogsfeature

 
 

Repository files navigation

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 v4.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 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
                        })));

}

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

About

Servicestack plugin that logs requests to seq

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 94.2%
  • PowerShell 5.8%