ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

Provide an option for disable the initialization of TraceTelemetry properties with the logging state

Open liguori opened this issue 3 years ago • 0 comments

The user should have control over the exact information to be send as Traces in Application Insights.

When instrumenting an ASP.NET Application, all the logs emitted via ILogger are sent to Application Insights as Traces initialized in the PopulateTelemetry method as follows:

  • Message = formatter(State)
  • CustomDimensions = all the items of the State dictionary

In some context the user just needs to rely on the Message and doesn't need all the information that the State object contains.

A good idea could be provide an option to the ApplicationInsightsLoggerOptions that disable this behavior, a bool property could be enough:

 public bool IncludeStateAsCustomDimensions { get; set; } = true;

So that by modifying this line: ApplicationInsightsLogger.cs#L171 taking account of the option:

  if (this.applicationInsightsLoggerOptions.IncludeStateAsCustomDimensions  && state is IReadOnlyCollection<KeyValuePair<string, object>> stateDictionary)
  {

the user can choose whether include the state or not.

liguori avatar Jul 26 '22 10:07 liguori