我有以下Azure函数:
[FunctionName("FunctionSync")]
public async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger _log) // where ILogger is Microsoft.Extensions.Logging.ILogger
{
try
{
// some code
}
catch (VerizonUnexpectedResponseException ex)
{
log.LogError($"{ex.Message}; response text: '{ex.ResponseText}'");
}
catch(VerizonUnsuccessfulResponseException failed_ex)
{
log.LogWarning($"Unexpected response; Error: '{failed_ex.Response.Error}', Description: '{failed_ex.Response.Description}'");
}
}所以,我写了一些消息给AI作为警告和错误,当某些条件为真时…现在我想创建警报通知(例如,发送到电子邮件),我转到Azure App Insights -> Rules -> create New Rule,但我不知道应该为它选择哪个信号名称?

发布于 2021-02-20 03:26:43
自定义日志搜索,其中的搜索可能如下所示
traces
| where message contains "some recognizable part of your message"或
exceptions
| where type contains "VerizonUnexpectedResponseException"
or type contains "VerizonUnsuccessfulResponseException"发布于 2021-02-22 14:09:43
您应该使用custom log search。
在创建警报规则时,对于resources,您应该选择已连接的Application Insights,而不是function app。然后,对于Condition,选择Custom log search。
根据您的代码,来自log.LogError和log.LogWarning的消息都将流入traces表。对于来自log.LogError的消息,severityLevel属性将被设置为3;对于来自log.LogWarning的消息,severityLevel属性将被设置为2。您还可以使用cloud_RoleName(这里,它应该是您的函数应用程序名称)属性来标识您的函数应用程序。
因此,在Custom log search中,查询应如下所示:
traces
| where severityLevel in (2,3)
| where cloud_RoleName == "function app name"然后,您可以继续为此警报规则配置其他设置。
https://stackoverflow.com/questions/66283549
复制相似问题