Azureblue.ApplicationInsights.RequestLogging
1.0.1
See the version list below for details.
dotnet add package Azureblue.ApplicationInsights.RequestLogging --version 1.0.1
NuGet\Install-Package Azureblue.ApplicationInsights.RequestLogging -Version 1.0.1
<PackageReference Include="Azureblue.ApplicationInsights.RequestLogging" Version="1.0.1" />
paket add Azureblue.ApplicationInsights.RequestLogging --version 1.0.1
#r "nuget: Azureblue.ApplicationInsights.RequestLogging, 1.0.1"
// Install Azureblue.ApplicationInsights.RequestLogging as a Cake Addin #addin nuget:?package=Azureblue.ApplicationInsights.RequestLogging&version=1.0.1 // Install Azureblue.ApplicationInsights.RequestLogging as a Cake Tool #tool nuget:?package=Azureblue.ApplicationInsights.RequestLogging&version=1.0.1
Extended HTTP request & response logging with Application Insights
Introduction
This nuget package provides a custom middleware that allows to write the body of an HTTP request/response to a custom dimension.
Features
- Log request & response body to Application Insights
- Configure maximum length to store
- Provide optional cut off text
- Configure name of custom dimension key
- Filter based on request path and content type
Installation
Just pull in the nuget package like so:
dotnet add package Azureblue.ApplicationInsights.RequestLogging
Then you'll have to register the middleware in your Startup
class with your container.
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]);
services.AddRequestLogging(new RequestLoggerOptions
{
PropertyKey = "RequestBody",
HttpVerbs = new[] { "POST" },
MaxSize = 100,
CutOffText = "SNIP",
ContentType = "application/json",
Path = "/"
});
services.AddRequestLogging(new RequestLoggerOptions
{
PropertyKey = "RequestBody",
HttpVerbs = new[] { "POST" },
MaxSize = 100,
CutOffText = "SNIP",
ContentType = "application/json",
Path = "/"
});
// ...
}
Finally configure the request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseRequestLogging();
app.UseResponseLogging();
}
// ...
}
A word of warning! Writing the content of an HTTP body to Application Insights might reveal sensitive user information that otherwise would be hidden and protected in transfer via TLS. So use this with care and only during debugging or developing!
Configuration
Use an instance of RequestLoggerOptions
and ResponseLoggerOptions
to configure the middleware. See the default values below.
RequestLoggerOptions
public class RequestLoggerOptions
{
public string PropertyKey { get; set; } = "RequestBody";
public string[] HttpVerbs { get; set; } = { "POST", "PUT" };
public int MaxSize { get; set; } = 100;
public string CutOffText { get; set; } = "\n---8<------------------------\nSSHORTENED-DUE-TO-MAXSIZE-LIMIT";
public string? ContentType { get; set; } = null;
public string Path { get; set; } = "/";
}
ResonseLoggerOptions
public class ResponseLoggerOptions
{
public string PropertyKey { get; set; } = "ResponseBody";
public int MaxSize { get; set; } = 100;
public string CutOffText { get; set; } = "\n---8<------------------------\nSSHORTENED-DUE-TO-MAXSIZE-LIMIT";
public string? ContentType { get; set; } = MediaTypeNames.Application.Json;
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.ApplicationInsights (>= 2.18.0)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.