Skip to content

fastchannel/restsharp-serilog-auto

 
 

Repository files navigation

Codacy Badge Build status codecov NuGet Downloads NuGet Version

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")
                .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
  • Uri
  • Host
  • Path
  • Query
  • Body
  • RequestHeaders
  • StatusCode
  • StatusDescription
  • ResponseStatus
  • ProtocolVersion
  • IsSuccessful
  • ErrorMessage
  • ErrorException
  • Content
  • ContentEncoding
  • ContentLength
  • ContentType
  • ResponseHeaders

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

About

Automatic log request and response from RestSharp using Serilog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%