Giter VIP home page Giter VIP logo

servicestack-seq-requestlogsfeature's Introduction

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

servicestack-seq-requestlogsfeature's People

Contributors

aiyyo avatar englerj avatar olibanjoli avatar rsafier avatar tobiaszuercher avatar wwwlicious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

servicestack-seq-requestlogsfeature's Issues

can i log sql query with single request log?

Hi,
can i log sql query into request log?(via ServiceStack OrmLiteExecFilter)

i think queryFilter are not in one scope(context) with request.

can't find a way do this, can you help?

SeqRequestLogsFeature does not work with ServiceStack v5.9

An error is thrown on AppHost.Init().
Error message is Method 'get_IgnoreFilter' in type 'ServiceStack.Seq.RequestLogsFeature.SeqRequestLogger' from assembly 'ServiceStack.Seq.RequestLogsFeature, Version=5.1.0.104, Culture=neutral, PublicKeyToken=null' does not have an implementation..

Responsible line is define in AppHost.Configure() at this line.

if (AppSettings.Get("SeqEnabled", false))
    plugins.Add(new SeqRequestLogsFeature { SeqUrl = AppSettings.GetString("SeqUrl") });

If I ignore this line, no error is thrown.

Thank you for your time!

option to filter RawHttpHandler requests

hey,
thank you for your fantastic plugin.

i have a little issue and i'm yet not sure how to solve it.
you provide the possibility to filter out certain requests by type. I'm looking at the ServerSentEventsFeature Heartbeat requests.

Our log is spammed with

HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.
HTTP POST /event-heartbeat responded 200 in 0ms.

The heartbeats are handled as a rawhttp handler so the requestType is always null.

        protected bool ExcludeRequestType(Type requestType)
        {
            return ExcludeRequestDtoTypes != null
                   && requestType != null
                   && ExcludeRequestDtoTypes.Contains(requestType);
        }

and it will be logged always. I'm not really interested in all the heartbeats of all clients. What would be an appropriate way to filter it out? Maybe an additional string filter/regex property to filter certain urls out?

Disable requestBodyTracking when upload file in .net core

Hi, i have a problem when using seq-requestlogger with netcore.
my setting is like below

 Plugins.Add(new SeqRequestLogsFeature
           {
               SeqUrl = "http://localhost:5341",
               EnableRequestBodyTracking = true,
               EnableResponseTracking = true,
               EnableSessionTracking = true,
               ExcludeRequestDtoTypes = new[] { typeof(SeqRequestLogConfig), typeof(ImageUploadDto) },
               HideRequestBodyForRequestDtoTypes = new[] { typeof(SeqRequestLogConfig), typeof(ImageUploadDto) },
               AppendProperties = (request, dto, response, duration) => new Dictionary<string, object> { { "System", "Mobile.Lis" } }
               ,
                SkipLogging = (request) => {
                    var skip = request.OperationName == typeof(ImageUploadDto).GetOperationName();
                    return skip; }
           });

and when i upload file via ImageUploadDto, it will thown an error:

Unexpected end of Stream, the content may have already been read by another component.

searched a while and find answer from ServiceStack Forum:
https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/9

ServiceStack/ServiceStack@166e785

i will clone this repo give a try, it looks like netcore's issue with form data.

Package will not install

I am attempting to install the package via Nuget and am getting the error:

Could not install package 'ServiceStack.Seq.RequestLogsFeature 4.0.57.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

What am I missing?

Thanks

The version should be all right, but the following error occurred.

"startUpErrors": [{
"errorCode": "TypeLoadException",
"message": "Method 'get_RequestLogFilter' in type 'ServiceStack.Seq.RequestLogsFeature.SeqRequestLogger' from assembly 'ServiceStack.Seq.RequestLogsFeature, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.",
"stackTrace": "[Object: 11/21/2018 14:34:09]:\n[REQUEST: ]\nSystem.TypeLoadException: Method 'get_RequestLogFilter' in type 'ServiceStack.Seq.RequestLogsFeature.SeqRequestLogger' from assembly 'ServiceStack.Seq.RequestLogsFeature, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.\n at ServiceStack.Seq.RequestLogsFeature.SeqRequestLogsFeature.get_Logger()\n at ServiceStack.Seq.RequestLogsFeature.SeqRequestLogsFeature.ConfigureRequestLogger(IAppHost appHost)\n at ServiceStack.Seq.RequestLogsFeature.SeqRequestLogsFeature.Register(IAppHost appHost)\n at ServiceStack.ServiceStackHost.LoadPluginsInternal(IPlugin[] plugins)",
"errors": []
}],

Add batching to seq http posts

Currently the IRequestLogger creates a post for every call to Log which is inefficient.
Instead queue the logs as they come in and process the sending to seq in batches.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.