Код: Выделить всё
public class StorageUtilityHandler
{
private readonly ILogger _logger;
private readonly IBusinessLogic _businessLogic;
public StorageUtilityHandler(ILogger logger, IBusinessLogic businessLogic)
{
_logger = logger;
_businessLogic = businessLogic;
}
[Function("LogProcessorQueue")]
public static Task ProcessLogQueueAsync(
[ServiceBusTrigger("%LogServiceBusQueue%", Connection = "ServiceBusConnection")] string logFileMessage, ILogger log)
{
if (logFileMessage != null)
{
try
{
LogEntity? logEntity = JsonSerializer.Deserialize(logFileMessage);
if (logEntity != null)
{
// If ERROR then send out Email
if (logEntity.Message.Contains("ERROR"))
{
var _email = new EmailService();
_email.SendLogError(logEntity);
}
var storageConnection = Environment.GetEnvironmentVariable("StorageConnection");
var loggingTableName = Environment.GetEnvironmentVariable("LoggingTableName");
TableClient tableClient = new(storageConnection, loggingTableName);
// Create the table if it doesn't already exist to verify we've successfully authenticated.
tableClient.CreateIfNotExists(); //Remove in PROD
tableClient.AddEntity(logEntity);
}
}
catch (Exception ex)
{
log.LogError($"Error processing Log message. {ex.Message} | {ex.StackTrace} | {ex.InnerException}");
}
}
return Task.CompletedTask;
}
}
< /code>
Program.cs
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.AddTransient();
})
.Build();
< /code>
All my Service Bus messages from this FA are going into the Dead Letter queue. Looking at the messages in the Dead Letter queue, they look correct. When I look at the logs from Application Insights, I get the following error about ILogger< /code> null. < /p>
operation_name: logprocessorQueue < /p>
Исключение: System.argumentNullexception: значение не может быть нулевым. (Parameter 'logger')
at System.ThrowHelper.Throw(String paramName)
at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)
at Microsoft.extensions.logging.loggerextensions.logerror (ilogger logger, строковое сообщение, объект [] args)
Подробнее здесь: https://stackoverflow.com/questions/785 ... ogger-null