我正在实现自定义的ApplicationInsights日志记录器,能够将所有日志写入正确的位置,如跟踪、异常和请求,但是在跟踪和异常中OperationId为空。
昨天我使用相同的代码,在所有表格中获取到了OperationId。之后我尝试了多线程方案,但效果不佳。现在我重新开始使用简单的代码,但无法看到OperationId。
我的代码有什么问题?
public static class Function2
{
private static TelemetryClient telemetryClient = new TelemetryClient(new Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration
{
InstrumentationKey = "********-****-********-****"
});
[FunctionName("Function2")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)]HttpRequestMessage req)
{
RequestTelemetry requestTelemetry = new RequestTelemetry { Name = "Function2" };
var operation = telemetryClient.StartOperation(requestTelemetry);
telemetryClient.TrackTrace("trace message", SeverityLevel.Error);
telemetryClient.TrackException(new System.Exception("My custom exception"));
operation.Telemetry.Success = true;
telemetryClient.StopOperation(operation);
return req.CreateResponse(HttpStatusCode.OK, "Hello ");
}
}