Show / Hide Table of Contents

Class HostApiMiddlewareExtension

Extension for HostApiMiddleware.

Inheritance
System.Object
HostApiMiddlewareExtension
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: StoneCo.Framework.DependencyInjection.Extension
Assembly: cs.temp.dll.dll
Syntax
public static class HostApiMiddlewareExtension

Methods

AddHostApiLog(IServiceCollection, IConfiguration)

This is a extension method to encapsulate dependency injection of the Error Log and/or Request Log.

In this extension, the options for Error Log, Request Log and the dependecy injection for HttpClient are set to call log API.

note

To use this extension, see the example below.

Declaration
public static IServiceCollection AddHostApiLog(this IServiceCollection services, IConfiguration configuration)
Parameters
Type Name Description
IServiceCollection services

The IServiceCollection to add the service to.

IConfiguration configuration

Represents a set of key/value application configuration properties.

Returns
Type Description
IServiceCollection

A reference to this instance after the operation has completed.

Examples

To use appsettings.json file for Error Log.

{
  "Logs": {
    "Error": {
      "Enable": true,
      "Host": "https://domain-of-api-log.com/"
    }
  }
}

To use configurations in database.

key = "Logs:Error:Enable"; value = true;
key = "Logs:Error:Host"; value = "https://domain-of-api-log.com/";

To use appsettings.json file for Request Log.

{
  "Logs": {
    "Request": {
      "Enable": true,
      "Host": "https://domain-of-api-log.com/"
    }
  }
}

To use configurations in database.

key = "Logs:Request:Enable"; value = true;
key = "Logs:Request:Host"; value = "https://domain-of-api-log.com/";

This sample should by applied on the infrastructure layer in DIFactory class.

public class DIFactory
{
    public static void ConfigureDI(IServiceCollection services, IConfiguration configuration)
    {
        services.AddHostApiLog(configuration);
    }
}
warning

This setting is required whenever you use HostApiMiddleware and there is a need to create a error log and/or request log for each call.

Exceptions
Type Condition
System.ArgumentNullException

If the log is enable and host is null, an exception is thrown with message 'If error logging is enabled, the host can not be null. For more information on how to enable or disable the error log see the documentation at http://docfx.stone.com.br/StoneCo.Framework.Host.Api/StoneCo.Framework.Host.Api.Middlewares.ErrorHandlerMiddleware.html .'.

System.ArgumentNullException

If the log is enable and host is null, an exception is thrown with message 'If request logging is enabled, the host can not be null. For more information on how to enable or disable the request log see the documentation at http://docfx.stone.com.br/StoneCo.Framework.Host.Api/StoneCo.Framework.Host.Api.Middlewares.RequestLogMiddleware.html .'

Back to top Generated by DocFX