Class HostApiMiddlewareExtension
Extension for HostApiMiddleware.
Inheritance
Inherited Members
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 |
System.ArgumentNullException | If the log is enable and host is null, an exception is thrown with message |