Open cmeeren opened 2 years ago
Hi Chris, I think you can quite easily adjust the TraceTelemetryConverter like:
internal class CustomTraceTelemetryConverter: TraceTelemetryConverter
{
public override void ForwardPropertiesToTelemetryProperties(LogEvent logEvent, ISupportProperties telemetryProperties, IFormatProvider formatProvider)
{
base.ForwardPropertiesToTelemetryProperties(
logEvent,
telemetryProperties,
formatProvider,
includeLogLevel: false,
includeRenderedMessage: true,
includeMessageTemplate: true);
}
}
and then
.WriteTo.ApplicationInsights(
telemetryConfiguration,
new CustomTraceTelemetryConverter());
should do the trick.
Thanks! Would it be possible for you to include it by default? I think it makes sense to always include the rendered message (for simpler search and display in AI), and as I understand it, it's a non-breaking change.
Also, doing this by defaults avoids the caveat that with your workaround, I rely on the implementation detail that TelemetryConverter.Traces
is a TraceTelemetryConverter
. (Statically it is typed to ITelemetryConverter
, and the implementing type could change without my knowing it. I would then not pick up those changes if I use my own converter.)
Hi @cmeeren . Actually I am just a passerby, that had the same issue as you. I think the current default behavior is probably because of the way ExceptionTelemetry is handled in the Microsoft.ApplicationInsights sdk. There they have some logic to parse the Message out of the Exceptions.
Description
When logging exceptions, the sink sends the message template, but not the actual rendered message.
Reproduction
Config:
Log statement:
The following is sent to AI:
Expected behavior
Just like traces, the data send for exceptions contains the actual rendered log message (above,
Starting retry 1 of 3
) so that it can be displayed in AI.If there is no standard field for this, a custom property (e.g.
RenderedMessage
, or another suitable name) is fine with me and would solve all my problems.Relevant package, tooling and runtime versions
Using Serilog.Sinks.ApplicationInsights 4.0.0 on .NET 6.