platforms | author |
---|---|
ASP.NET Core 2.2 Web API, Application Insights |
amigup |
Implements to log Request Body in application insights after removing the sensitive information.
Download the package from nuget.org
You want to log the Request Body in application Insights after removing the sensitive information so that in Appliation Insights the request body payload can be viewed.
This package is built on
- ASP.Net Core 2.2 Web API.
- Microsoft.ApplicationInsights 2.8.1
- Newtonsoft.Json 12.0.1
- Add
RequestLogActionFilterAttribute
filter in the MVC pipeline.
services.AddMvc(options =>
{
options.Filters.Add<RequestLogActionFilterAttribute>();
});
You can attach PII
attribute over Properties, Class and Action method parameters.
If PII
attribute is attached over property then in Application Insights request log, the actual value is substituted with PII Data
string literal.
public class User
{
[PII]
public string Id { get; set; }
public string Name { get; set; }
public DateTime AnneviseryDate { get; set; }
[PII]
public int LinkId { get; set; }
public List<Address> Addresses { get; set; }
}
If PII
attribute is attached over class then object is not logged in Application Insights request log.
[PII]
public class User
{
}
If PII
attribute is attached over parameter then object is not logged in Application Insights request log.
[HttpPost]
public void Post([FromBody, PII] User user)
{
}
The repository contains a sample application to demostrate the usage of ApplicationInsights.Extension.RequestLogging
.