Git Product home page Git Product logo

stravaig.aspnet.diagnostics.reqres's Introduction

Stravaig.AspNet.Diagnostics.ReqRes

A piece of middleware for ASP.NET Core applications that logs the request / response.

  • Build Stravaig.AspNet.Diagnostics.ReqRes

CAUTION: This package should be used sparingly. It will slow requests, and may expose PII (Personally Identifiable Information) or secrets in logs which may be a violation of GDPR.

Usage

First, you need to add the services required for this middleware to run. There are three options.

Option 1, sets up the default. So requests and responses are logged at the information level.

public void ConfigureServices(IServiceCollection services)
{
  services.AddStravaigReqResLogging();
  // Add services required by other components of your app
}

Option 2, allows you to pass in a settings object, which permits you to define which logging level you want to use:

public void ConfigureServices(IServiceCollection services)
{
  var settings = new ReqResLoggingSettings{ LogLevel = LogLevel.Debug };
  services.AddStravaigReqResLogging(settings);
  // Add services required by other components of your app
}

Option 3, allows you to take the configuration from the system's configuration (e.g. appsettings.json, etc.). This expects the configuration to be located at Stravaig:ReqResLogging. If it is not found then the default settings will be used:

public class Startup
{
  public Startup(IConfiguration configuration)
  {
    // Allow the framework to inject an IConfiguration object
    Configuration = configuration;
  }

  public IConfiguration Configuration { get; }

  // This method gets called by the runtime. Use this method to add services to the container.
  public void ConfigureServices(IServiceCollection services)
  {
    // Add the Req/Res logging library using the IConfiguration object
    services.AddStravaigReqResLogging(Configuration);
    // Add services required by other components of your app
  }

Finally, Add the middleware to your application's pipeline in the Configure method. It should go near the start so that it can pick up the request as it comes in (just in case any other middleware modifies it) and so that the all the other middleware can add to the response for those additions to be logged too.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseRequestResponseDiagnostics();
    // Add other things to your app pipeline.
}

Settings

In the configuration the settings are at:

{
  "Stravaig" :{
    "ReqResLogging":{
      "Enabled": true,
      "LogLevel": "Information"
    }
  }
}

Or, you can configure it directly with the ReqResLoggingSettings class.

Enabled

Default: true

When true, this will ensure that the middleware is added to the pipeline when app.UseRequestResponseDiagnostics() is called, otherwise the middleware won't be added. This allows the call to stay in the application and the pipeline based on a configuration setting.

LogLevel

Default: Information

This maps to the Microsoft.Extensions.Logging.LogLevel enum. It defines the log level the request/response logs are to be logged at.

stravaig.aspnet.diagnostics.reqres's People

Contributors

colinangusmackay avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

stravaig.aspnet.diagnostics.reqres's Issues

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.