我在产品环境中有一些错误警报,如果它们触发了,我希望得到警报。问题是它们从未触发过,因此我无法在门户中看到它们。
谢谢!
答案 0 :(得分:1)
我看到您有一个try / catch,然后您可以考虑向应用程序见解发送自定义错误消息(此处的逻辑是,由于您知道自定义错误消息,因此可以使用此预定义的消息来创建警报),通过在catch块中使用以下代码:
try
{
//your code
}
catch
{
//if you're using ILogger which is integrated with application insights.
_logger.LogError(new Exception(),"custom error: xxxx");
//your other code
}
然后导航至Azure门户->应用程序见解->日志:
1。按如下方式编写查询:
exceptions
| where customDimensions.FormattedMessage == "custom error: xxxx"
2。选择查询,然后单击运行按钮。
3。最后,单击“新建警报规则”按钮以创建警报。
答案 1 :(得分:1)