我尝试了很多东西,但是我可以强制AzFn理解调用失败的唯一方法是抛出异常而不处理它.因此,如果我返回一个HttpResponseException,AzFn会认为调用是成功的.那感觉不对.
catch (Exception ex)
{
logger.Error($"{nameof(ex)}: {ex.Message}", ex);
response = req.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message, ex);
}
Run Code Online (Sandbox Code Playgroud)
这应该产生一个标记为失败的调用,但它不会.
在 Kubernetes (Minikube) 上使用 EFK 堆栈。有一个使用 Serilog 的 asp.net 核心应用程序以 Json 的形式写入控制台。日志确实会发送到 Elasticsearch,但它们到达未解析的字符串,进入“日志”字段,这就是问题所在。
这是控制台输出:
{
"@timestamp": "2019-03-22T22:08:24.6499272+01:00",
"level": "Fatal",
"messageTemplate": "Text: {Message}",
"message": "Text: \"aaaa\"",
"exception": {
"Depth": 0,
"ClassName": "",
"Message": "Boom!",
"Source": null,
"StackTraceString": null,
"RemoteStackTraceString": "",
"RemoteStackIndex": -1,
"HResult": -2146232832,
"HelpURL": null
},
"fields": {
"Message": "aaaa",
"SourceContext": "frontend.values.web.Controllers.HomeController",
"ActionId": "0a0967e8-be30-4658-8663-2a1fd7d9eb53",
"ActionName": "frontend.values.web.Controllers.HomeController.WriteTrace (frontend.values.web)",
"RequestId": "0HLLF1A02IS16:00000005",
"RequestPath": "/Home/WriteTrace",
"CorrelationId": null,
"ConnectionId": "0HLLF1A02IS16",
"ExceptionDetail": {
"HResult": -2146232832,
"Message": "Boom!",
"Source": null,
"Type": "System.ApplicationException"
}
}
} …
Run Code Online (Sandbox Code Playgroud) 此查询花费 265 RU/s:
SELECT top 1 * FROM c
WHERE c.CollectPackageId = 'd0613cbb-492b-4464-b66b-3634b5571826'
ORDER BY c.StartFetchDateTimeUtc DESC
StartFetchDateTimeUtc是一个字符串属性,使用 Cosmos API 序列化
此查询花费 5 RU/s:
SELECT top 1 * FROM c
WHERE c.CollectPackageId = 'd0613cbb-492b-4464-b66b-3634b5571826'
ORDER BY c._ts DESC
_ts是一个内置字段,一个基于 Unix 的数字时间戳。
结果示例(仅包含该字段和_ts):
"StartFetchDateTimeUtc": "2017-08-08T03:35:04.1654152Z",
"_ts": 1502163306
索引已就位,并遵循如何配置可排序字符串/时间戳的建议和教程。看起来像:
{
"path": "/StartFetchDateTimeUtc/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
}
]
}