I could really need some help.
I want to use NLog with Azure Functions v2 (Target Framework .NET Core 2.2) – and have created a
Startup : FunctionsStartup
class decorated with
[assembly: FunctionsStartup(typeof(PmsFunctions.Startup))]
And created this method
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.ClearProviders();
loggingBuilder.SetMinimumLevel(LogLevel.Trace);
loggingBuilder.AddNLog();
}).BuildServiceProvider();
}
In constructor of the Startup class I have created the configuration of NLog using code:
var mailTarget = new MailTarget("mandrill")
{
Html = true,
AddNewLines = true,
ReplaceNewlineWithBrTagInHtml = true,
Subject = "XXXXX",
To = "john@doe.com,
From = "john@doe.com",
Body = "Message: ${message}${newline}${newline}Date: ${date}${newline}${newline}Exception: ${exception:format=tostring}${newline}${newline}",
SmtpUserName = "XXXXXXX",
SmtpPassword = "XXXXXXX",
SmtpAuthentication = SmtpAuthenticationMode.Basic,
SmtpServer = "XXXXXXXX",
SmtpPort = 587
};
var bufferedMailTarget = new BufferingTargetWrapper("bufferedMandril", mailTarget)
{
SlidingTimeout = false,
BufferSize = 100,
FlushTimeout = 10000
};
config.AddTarget(bufferedMailTarget);
var mailRule = new LoggingRule("*", NLog.LogLevel.Warn, bufferedMailTarget);
config.LoggingRules.Add(mailRule);
var logger = NLogBuilder.ConfigureNLog(config).GetCurrentClassLogger
I try to use the logger in the functons by using the injected ILogger. It works perfectly locally but it is completely “dead” when using Azure. I guess it is the way I configure the NLog.
How should I do it the right way?