App Insight中的任务数据库错误

时间:2016-05-15 01:23:50

标签: c# multithreading entity-framework

我遇到了Application Insight报告在保存到数据库时报告EF上下文异常的问题。

enter image description here

private async Task SendAsync(IEmailDataModel model)
{
    await _emailHelper.SendAsync(model.To, model.Subject, model.Body);

    /* send messages */
    var logEmail = new LogEmail
    {
        UserSignatureId = GetUserSignature(model.To),
        LogTaskId = model.LogTaskId,
        Type = (int)model.Type,
        Subject = model.Subject,
        From = _defaultConfig.SupportEmailAddress,
        To = model.To,
        Content = model.Body,
        CreatedOn = DateTime.UtcNow
    };

    _unit.Repository<LogEmail>().Insert(logEmail);
    await _unit.SaveChangesAsync();
}

我怎么想调试这个?我正在使用带有TimerTrigger的WebJobs。

1 个答案:

答案 0 :(得分:0)

如果App Insights告诉您发生了此异常,那是因为异常确实发生了。

有可能,在堆栈的某个地方,无论谁调用SendAsync都没有等待,或者更远,更远,有人没有在这些异步方法之一上等待等待某点。

因此,当更改被拒绝时(由于验证原因,内部异常就是这样),没有人会抓住它并告诉任何人,因此终结器会抛出没人处理的异常。

注册应用程序洞察以记录未处理的异常,因此它向您显示您可能不知道的异常。