NeoConcept.LogHttpCore
3.0.0
dotnet add package NeoConcept.LogHttpCore --version 3.0.0
NuGet\Install-Package NeoConcept.LogHttpCore -Version 3.0.0
<PackageReference Include="NeoConcept.LogHttpCore" Version="3.0.0" />
paket add NeoConcept.LogHttpCore --version 3.0.0
#r "nuget: NeoConcept.LogHttpCore, 3.0.0"
// 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
.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 requestsLogExtension
: 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 | Versions 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. |
-
net5.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.Extensions.Logging (>= 5.0.0)
- Microsoft.Net.Http.Headers (>= 2.2.8)
- neoconcept.mongorepository (>= 5.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.