title: How to configure NLog for Azure Functions?
body: <p>I could really need some help.</p>
  
  <p>I want to use NLog with Azure Functions v2 (Target Framework .NET Core 2.2) – and have created a</p>
  
  <pre><code>Startup : FunctionsStartup
  </code></pre>
  
  <p>class decorated with</p>
  
  <pre><code>[assembly: FunctionsStartup(typeof(PmsFunctions.Startup))]
  </code></pre>
  
  <p>And created this method</p>
  
  <pre><code>public override void Configure(IFunctionsHostBuilder builder)
  {
      builder.Services.AddLogging(loggingBuilder =&gt;
      {
          loggingBuilder.ClearProviders();
          loggingBuilder.SetMinimumLevel(LogLevel.Trace);
          loggingBuilder.AddNLog();
      }).BuildServiceProvider();
  }
  </code></pre>
  
  <p>In constructor of the Startup class I have created the configuration of NLog using code:</p>
  
  <pre><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
  </code></pre>
  
  <p>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. </p>
  
  <p>How should I do it the right way?</p>