public static IServiceCollection AddSerilogWithInsights()

in src/Shared/Configuration/Extensions/LoggingExtensions.cs [32:55]


        public static IServiceCollection AddSerilogWithInsights<T>(this IServiceCollection collection)
        {
            collection.SetupSerilog((provider, loggerConfiguration) =>
            {
                loggerConfiguration
                    .MinimumLevel.Information()
                    .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                    .MinimumLevel.Override("System", LogEventLevel.Warning)
                    .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                    .Enrich.FromLogContext()
                    .Enrich.WithProperty("ApplicationName", typeof(T).Assembly.GetName().Name)
                    // For some reason, the Function application skips the 'Startup' extension when reference to AspNetCore.Hosting appears ... Bug in function skd ?
                    //      https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#logging-services
                    .WriteTo.ApplicationInsights(TelemetryConfiguration.CreateDefault(),
                        TelemetryConverter.Traces,
                        LogEventLevel.Information)
                    .WriteTo.Console(
                        outputTemplate:
                        "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}",
                        theme: AnsiConsoleTheme.Literate);
            });

            return collection;
        }