NeoConcept.LogHttpCore 3.0.0

dotnet add package NeoConcept.LogHttpCore --version 3.0.0
NuGet\Install-Package NeoConcept.LogHttpCore -Version 3.0.0
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="NeoConcept.LogHttpCore" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NeoConcept.LogHttpCore --version 3.0.0
#r "nuget: NeoConcept.LogHttpCore, 3.0.0"
#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.
// Install NeoConcept.LogHttpCore as a Cake Addin
#addin nuget:?package=NeoConcept.LogHttpCore&version=3.0.0

// Install NeoConcept.LogHttpCore as a Cake Tool
#tool nuget:?package=NeoConcept.LogHttpCore&version=3.0.0

Nuget

.NET NeoConcept.LogHttpCore

NeoConcept.LogHttpCore provides a way to add a middleware to log the request and response of an API (uses ILogger extension or MongoDb mode)

Getting Started

1.Install the standard Nuget package into your ASP.NET Core application.

Package Manager : Install-Package NeoConcept.LogHttpCore -Version 3.0.0
CLI : dotnet add package --version 3.0.0 NeoConcept.LogHttpCore

2.In the Configure method of Startup.cs, Insert the middleware.

using NeoConcept.LogHttpCore;
public void Configure(IApplicationBuilder app, IWebHostEnvironment env){
...
app.UseAspNetcoreNeoLogRequest("LogMode");
app.UseAspNetcoreNeoLogResponse("LogMode");
...
}

we have 3 mode to log the request and response :

  • LogRequestNone:does not log any HTTP requests
  • LogExtension: log the request and response of an API using ILogger extension.
  • LogDatabase: log the request and response of an API in a database Collection.

Replace "LogMode" with a mode of your choice (LogRequestNone or LogExtension or LogDatabase)

LogExtension Mode

using NeoConcept.LogHttpCore;
public void Configure(IApplicationBuilder app, IWebHostEnvironment env){
...
app.UseAspNetcoreNeoLogRequest("LogExtension");
app.UseAspNetcoreNeoLogResponse("LogExtension");
...
}

LogDatabase Mode

using NeoConcept.LogHttpCore;
public void Configure(IApplicationBuilder app, IWebHostEnvironment env){
...
 app.UseAspNetcoreNeoLogRequest("LogDatabase",
                options =>
                {
                    options.AppName = Configuration["AppName"];
                    options.ConnectionString = "mongodb://dbuser:password@host:port/?tls=true";
                    options.DatabaseName = "DbProd";
                });

 app.UseAspNetcoreNeoLogResponse("LogDatabase",
                options =>
                {
                    options.AppName = Configuration["AppName"];
                    options.ConnectionString = "mongodb://dbuser:password@host:port/?tls=true";
                    options.DatabaseName = "DbProd";
                });
...
}

In LogDatabase Mode, there will be 2 collections: LogHttpRequest and LogHttpRequest

LogHttpRequest Collection

 [CollectionName("LogHttpRequest")]
    [BsonIgnoreExtraElements]
    public class LogHttpRequest
    {
        public DateTime Date { get; set; }
        public string AppName { get; set; }
        public string Host { get; set; }
        public string Url { get; set; }
        public string HttpMethod { get; set; }
        public string HttpScheme { get; set; }
        public string UserAgent { get; set; }
        public string UserIp { get; set; }
        public List<HttpHeader> HttpHeaders { get; set; }
        public string HttpBody { get; set; }
        [BsonId]
        [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
        public string Id { get; set; }
        [BsonIgnoreIfNull]
        public string CreatedBy { get; set; }
        [BsonIgnoreIfNull]
        public string UpdatedBy { get; set; }
        [BsonIgnoreIfNull]
        public DateTime? UpdatedDate { get; set; }
        public DateTime? CreatedDate { get; set; }
        public string Referer { get; set; }
    }

LogHttpResponse Collection

 [CollectionName("LogHttpResponse")]
    [BsonIgnoreExtraElements]
    public class LogHttpResponse
    {
        public DateTime Date { get; set; }
        public string AppName { get; set; }
        public string Host { get; set; }
        public string Url { get; set; }
        public string HttpMethod { get; set; }
        public string HttpScheme { get; set; }
        public string UserAgent { get; set; }
        public string UserIp { get; set; }
        public List<HttpHeader> HttpHeaders { get; set; }
        public string HttpBody { get; set; }
        [BsonId]
        [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
        public string Id { get; set; }
        [BsonIgnoreIfNull]
        public string CreatedBy { get; set; }
        [BsonIgnoreIfNull]
        public string UpdatedBy { get; set; }
        [BsonIgnoreIfNull]
        public DateTime? UpdatedDate { get; set; }
        public DateTime? CreatedDate { get; set; }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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. 
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
3.0.0 230 2/21/2023
2.0.0 404 1/12/2023