我有一个不在 Azure 中运行的 Azure 函数。它在本地运行,但在 Azure 中不运行。我有一个 try/catch,它没有捕获任何异常,但在日志中我得到“2020-07-26T12:23:00.021 [错误] 发生异常。” 不明白我做错了什么。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FluentEmail.Core;
using FluentEmail.Core.Models;
using FluentEmail.Mailgun;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace SendEmailFunction
{
public static class SendEmailFunction
{
private const string EmailSubject = "Collaboration proposal";
[FunctionName("SendEmailFunction")]
public static async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
try
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "1.csv");
List<string> lines = (await File.ReadAllLinesAsync(path)).ToList();
}
catch (Exception ex)
{
log.LogError($"An exception occured.", ex);
}
}
}
}
这是我得到的日志:
2020-07-26T12:35:00.007 [信息] C# 定时器触发函数执行于:7/26/2020 12:35:00 PM
2020-07-26T12:35:00.030 [错误] 发生异常。
2020-07-26T12:35:00.045 [信息] 执行“SendEmailFunction”(成功,Id=8b5d1b47-37de-4f84-8936-d31b19f0f73d,持续时间=42ms)