title: Azure Function Logging with Serilog to Application Insights
body: <p>We use <em>Azure Function V3</em> with dot net core 3.1 and log traces and events to <em>Application Insights</em>.
  This works quite fine. But we want to add object data to the log payload and therefore we use <em>Serilog</em>.</p>
  <p>If we use the <code>ILogger</code> interface from <code>namespace Microsoft.Extensions.Logging</code> the object won't be serialized correct.</p>
  <pre class="lang-cs prettyprint-override"><code>_logger.LogInformation(&quot;Test {@model}&quot;, testmodel);
  </code></pre>
  <p>If we use the <em>Serilog</em> interface it works and the data will be serialized in <em>Application Insights</em>:</p>
  <pre class="lang-cs prettyprint-override"><code>logger.Information(&quot;Test Serilog {@model}&quot;, testmodel);
  </code></pre>
  <p><img src="https://i.stack.imgur.com/DO9M1.png" alt="Serilog" /></p>
  <p>The <code>Startup.cs</code> looks like that:</p>
  <pre class="lang-cs prettyprint-override"><code>public class Startup : FunctionsStartup
  {
    public override void Configure(IFunctionsHostBuilder builder)
    {
      var logger = new LoggerConfiguration()
        .WriteTo.ApplicationInsights(TelemetryConfiguration.CreateDefault(), TelemetryConverter.Traces, Serilog.Events.LogEventLevel.Information)
        .Destructure.ToMaximumCollectionCount(10)
        .Destructure.ToMaximumDepth(4)
        .CreateLogger();
      builder.Services.AddLogging(c =&gt; c.AddSerilog(logger));
      // Add other services
    }
  }
  </code></pre>