This package is a middleware for ASP.NET application to log incoming requests. It does that by utilizing the Microsoft.Extensions.Logging library.
Depending on which environment you are using the requests will be logged differently.
You can also specify your own format by setting the RequestLogger
key in the appsettings.json
.
Require the nuget from the repository, add the services and the middleware in your startup class.
using SimonPrinz.RequestLogger;
public class Startup
{
public void ConfigureServices(IServiceCollection pServices)
{
[...]
pServices.AddRequestLogger();
[...]
}
public void Configure(IApplicationBuilder pApp)
{
[...]
pApp.UseRequestLogger();
[...]
}
}
Production: {RemoteAddress} - {RemoteUser} {DateTime} "{Method} {Url} {HttpVersion}" {Status} {ContentLength} "{Referrer}" "{UserAgent}"
Development (or everything else): {Method} {Url}{QueryString} {Status} {ResponseTime} ms - {ContentLength}
There are currently 12 variables that can be used. Most of them are subject to change, and will probably change at some point in the future (Watch the release notes for those changes!).
ContentLength
- The length of the responseDateTime
- The DateTime of the request in the format of ISO 8601HttpVersion
- The used HTTP versionMethod
- The used HTTP methodQueryString
- The query string of the requestReferrer
- The referrer of the requestRemoteAddress
- The remote address of the userRemoteUser
- The name of the claims identity associated with this claims principalResponseTime
- The response time in milliseconds of the responseStatus
- The status code of the responseUrl
- The request pathUserAgent
- The user-agent of the request