What EventId can i put when calling ILogger.LogError from Azure functions?

Viewed 4369

I'm using injected instance of ILogger instead of TraceWritter. The instance is injected fromm the Azure Function Runtime. I want to log a captured exception. The only overload of LogError that can accept a Exception is the extension method from class LoggerExtensions:

void LogError(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)

The problem is: this method receive a EventId as second argument, from where i can take the current EventId to use here? (I suppose each AF execution has his unique EventId).

2 Answers

You can create an extension method like this:

using System;

namespace Microsoft.Extensions.Logging
{
    public static class LoggerExtensions
    {
        public static void LogError(this ILogger logger, Exception ex, string message = null, params object[] args)
        {
            logger.LogError(default(EventId), ex, message, args);
        }
    }
}

https://github.com/aspnet/Logging/issues/367#issuecomment-313805976

Related