简体   繁体   中英

Log unsuccessful requests to Application Insights

According to the documentation and from what I can remember I've done before, it should be possible to log custom unsuccessful requests. But with this code, only the first one is written to Application Insights. I've tried it in a new vanilla solution without any filters.

using (var operation = client.StartOperation<RequestTelemetry>("SuccessfulRequest"))
{
    operation.Telemetry.Success = true;
}

using (var operation = client.StartOperation<RequestTelemetry>("UnsuccessfulRequest"))
{
    operation.Telemetry.Success = false;
}

Am I missing anything or isn't it possible to do it this way anymore?

It seems like setting a response code does the trick.

using (var operation = client.StartOperation<RequestTelemetry>("UnsuccessfulRequest"))
{
    operation.Telemetry.ResponseCode = "whatever";
    operation.Telemetry.Success = false;
}

According to the documentation provided your code would profile the custom code snippet

{
    operation.Telemetry.Success = false;
}

and not the entire request.

I understand that what you want is to set a property that marks the entire request as unsuccessful. Depending on your application you might want to have a look at Custom Telemetry Processors that let you modify your Telemetry items after they have run through your pipeline. A good example can be found here . Keep in mind that you have to adapt that sample code to your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM