I have an Azure Function that doesn't run in Azure. Locally it runs, but in Azure it doesn't. I have a try/catch in place, which doesn't catch any exception, but in the logs I get "2020-07-26T12:23:00.021 [Error] An exception occured." Don't understand what I'm doing wrong.
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);
}
}
}
}
This are the logs that I get:
2020-07-26T12:35:00.007 [Information] C# Timer trigger function executed at: 7/26/2020 12:35:00 PM
2020-07-26T12:35:00.030 [Error] An exception occured.
2020-07-26T12:35:00.045 [Information] Executed 'SendEmailFunction' (Succeeded, Id=8b5d1b47-37de-4f84-8936-d31b19f0f73d, Duration=42ms)
LogErroroverload for logging an exception: learn.microsoft.com/en-us/dotnet/api/… You're usingstring, object[]overload, rather thanexception, stringoverload. While this won't actually correct your issue, it will give you more information about the exception. Additionally, log something meaningful in the "string" message, like theex.Message.$""you should use placeholders in your messages and then pass values for those placeholders as the additional parameters. It's all based on support for structured logging (which AppInsights and Azure logging support)