Code Monkey home page Code Monkey logo

restsharp-serilog-auto's Introduction

Build Status NuGet Downloads NuGet Version Quality Gate Status Coverage

RestSharp.Serilog.Auto

Do you need log all communication made with RestSharp using your serilog configuration? Just install this package and register our client proxy for IRestClient.

IRestClient client = new RestClientAutolog("http://www.github.com");

Install via NuGet

PM> Install-Package RestSharp.Serilog.Auto

How to use

You can change error message, success message and logger configuration.

var loggerConfiguration = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .Enrich.WithMachineName()
                .Enrich.WithProperty("Domain", "MyDomain")
                .Enrich.WithProperty("Application", "MyProject")
                .Enrich.FromLogContext()
                .WriteTo.Seq("http://localhost:5341")
                .WriteTo.Console();

var restClientAutologConfiguration = new RestClientAutologConfiguration()
{
    MessageTemplateForSuccess = "{Method} {Uri} responded {StatusCode}", 
    MessageTemplateForError = "{Method} {Uri} is not good! {ErrorMessage}", 
    LoggerConfiguration = loggerConfiguration
};

IRestClient client = new RestClientAutolog("http://www.github.com", restClientAutologConfiguration);

Serilog uses Log.Logger as global. If you setup this on your application Startup/Bootstrap, it's not needed change logger configuration.

Variables to use in message templates

Properties created like (...).Enrich.WithProperty("Application", "MyProject") can be used in templates.

Default variables:

  • Agent
  • ElapsedMilliseconds
  • Method
  • Url
  • Host
  • Path
  • Query
  • RequestBody
  • RequestHeaders
  • StatusCode
  • StatusDescription
  • ResponseStatus
  • ProtocolVersion
  • IsSuccessful
  • ErrorMessage
  • ErrorException
  • Content
  • ContentEncoding
  • ContentLength
  • ContentType
  • ResponseHeaders

Setup global max length for exception properties

Use env var to change default value

  • SERILOG_ERROR_MESSAGE_MAX_LENGTH default value 256;
  • SERILOG_ERROR_EXCEPTION_MAX_LENGTH default value 1024;

How can I contribute?

Please, refer to CONTRIBUTING

Found something strange or need a new feature?

Open a new Issue following our issue template ISSUE_TEMPLATE

Changelog

See in nuget version history

Did you like it? Please, make a donate :)

if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.

BTC Wallet: 1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

restsharp-serilog-auto's People

Contributors

eduardosbcabral avatar leogojorge avatar renanklein avatar thiagobarradas avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

restsharp-serilog-auto's Issues

Dint working

            Logs.AutologConfig = new RestClientAutologConfiguration() {
                MessageTemplateForSuccess = "{Method} {Uri} responded {StatusCode}",
                MessageTemplateForError = "{Method} {Uri} is not good! {ErrorMessage}",
                LoggerConfiguration = new LoggerConfiguration()
                    .MinimumLevel.Debug()
                    .Enrich.FromLogContext()
                    .WriteTo.Console()
            };
            Serilog.Log.Information($"Logger running {true}");

...
new RestClientAutolog(url, Logs.AutologConfig) ...(make a success request)

Log didnt send any message to console.

Environment

Windows10
.NET Framework 4.8
Console Application

Logs / Stack trace

Insert your log/stack trace here

Same content being logged twice

Status

BUG REPORT

Steps

  1. Send any request via RestClientAutolog.
  2. Check logged request and response contents.

Expected behaviour

The program should log both request and response separately, with it's respective properties.

Actual behaviour

The program logs the same message twice, with the same properties and message template.

Brings in lots of unnecessary dependencies

Task: Remove PackUtils and JsonMasking.

These two libraries bring in about 60 unnecessary packages into a full framework project, things like dozens of Swashbuckle assemblies, Snappy.NET, Multiple MongoDB packages, about 30 Microsoft.AspnetCore.* packages.

Application went from 27 files at 12.5MB to 106 files at around 35 MB!

Packages.config BEFORE and AFTER:

image

Update default variables in README

The default variables listed in the README are out of date.

For example Uri should be Url and Body should be RequestBody.

In the meantime the real list of variables can be found here.

Update log configuration example in README

Using the example log configuration from the README does not allow referencing the default variables from the message template. i.e. {Method} will be printed as a string and not replaced with GET etc.

I recommend it is updated to include .Enrich.FromLogContext() like so:

var loggerConfiguration = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .Enrich.WithMachineName()
                .Enrich.WithProperty("Domain", "MyDomain")
                .Enrich.WithProperty("Application", "MyProject")
                .Enrich.FromLogContext() // This is the new line
                .WriteTo.Seq("http://localhost:5341")
                .WriteTo.Console();

var restClientAutologConfiguration = new RestClientAutologConfiguration()
{
    MessageTemplateForSuccess = "{Method} {Uri} responded {StatusCode}", 
    MessageTemplateForError = "{Method} {Uri} is not good! {ErrorMessage}", 
    LoggerConfiguration = loggerConfiguration
};

IRestClient client = new RestClientAutolog("http://www.github.com", restClientAutologConfiguration);

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.