VMtz84.Logger 2.0.4

dotnet add package VMtz84.Logger --version 2.0.4
                    
NuGet\Install-Package VMtz84.Logger -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VMtz84.Logger" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VMtz84.Logger" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="VMtz84.Logger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add VMtz84.Logger --version 2.0.4
                    
#r "nuget: VMtz84.Logger, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package VMtz84.Logger@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=VMtz84.Logger&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=VMtz84.Logger&version=2.0.4
                    
Install as a Cake Tool

Implementaciones de logger

Este nuget contiene 3 componentes principales RequestResponseMiddleware, ExceptionMiddleware y HttpLoger. A continuación se describe en que consiste cada componente Estas Implementaciones usan MongoDB como base de datos y esta construida en C#.

HttpLogger

El http loger intercepta la petición que se envia a traves del HppClientFactory, para agregar en el log

En el program agregue

builder.Services.AgregarHttpLoger();

Cuando haga la petición mediante el factory, agregue en el contructor de su servicio

private readonly IRequestGuidService _requestGuidService;

public Servicio(IRequestGuidService requestGuidService)
{
    _requestGuidService = requestGuidService
}

Agregue en el factory

using VMtz84.Logger.Extensores;

request.AgregarHeaderDeEncodedKey(_requestGuidService);

Para que quede como el siguiente fragmento

 using (var client = _clientFactory.CreateClient())
{
    var request = new HttpRequestMessage(HttpMethod.Get, _url);
    request.AgregarHeaderDeEncodedKey(_requestGuidService);
    var response = await client.SendAsync(request);
    if (response.IsSuccessStatusCode)
    {
        JObject jObject;

        jObject = JObject.Parse(await response.Content.ReadAsStringAsync());

        return Ok(new { Tarjeta = jObject["numeroDeTarjeta"].ToString() });
    }
    else
        throw new Exception(await response.Content.ReadAsStringAsync());
}

Asi el mismo guid queda registrado en los Middleware y pueda hacer la realación

RequestsResponsesMiddleware

Registra las peticiones de entrada y salida al servicio, para configurar es necesario agregar en el appsettings el segmento:

"LoggerMongoDb": {
    "ConnectionString": "mongodb://root:123456@localhost:27017/Logs?ssl=false&authSource=admin",
    "MongoDbName": "LogsDev",
    "CollectionNameRequests": "Peticiones",
    "CollectionNameExceptions": "ExceptionLogger",
    "CollectionNameHttpLogger": "HttpLogger",
    "ApplicationName": "TestDev",
    "ShowErrores": true,
    "ErrorMessage": "El minge ya esta chambiando",
    "Headers": {
      "author": "victor-martinez",
      "company": "sin-nigun-lugar"
    }
}

Si no encuentra la configuraciones arrojara una excepción.

En el Program.cs agregue el middleware, puede agregar uno, varios o combinaciones de ellos

app.UseHeaders();
app.AgregarHttpLoger();
app.UseRequestResponseExceptionYHeaders();
app.UseYException();
app.UseRequestResponse();

Nota

En Ocaciones no escribe el log, verifique y que no este el nugget

<PackageReference Include="MongoDB.Driver" Version="3.0.0" />

Quitelo limpie la solución, compile y pruebe de nuevo

Todo

  • Agregar controller test a peticón de configuración
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.4 188 8/20/2025
2.0.3 171 8/20/2025
2.0.2 186 8/20/2025
2.0.1 169 8/20/2025
2.0.0 176 8/19/2025
1.2.8 139 8/15/2025
1.2.7 164 11/23/2024
1.2.6 141 11/21/2024
1.1.6 158 11/8/2024
1.1.5 158 11/8/2024
1.1.3 159 11/7/2024

Middlewares para el registro de peticiones al servicio y excepciones