Ejemplo n.º 1
0
        private static void Configure(LoggerConfiguration loggerConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration)
        {
            var aiKey = configuration.GetApplicationInsightKey();

            if (!string.IsNullOrEmpty(aiKey))
            {
                // TODO: as soon as IHostBuilder will be used, use add serilog method which gets telemetry client from services
                loggerConfiguration
                .WriteTo
                .ApplicationInsights(aiKey, new TraceTelemetryConverter());
            }

            loggerConfiguration
            .Enrich.FromLogContext()
            .Enrich.WithMachineName()   // easy to correllate with cloud machine
            .Destructure.ToMaximumCollectionCount(42)
            .Destructure.ToMaximumStringLength(2048)
            .Destructure.ToMaximumDepth(2)
            .Enrich.WithExceptionDetails(
                new DestructuringOptionsBuilder()
                .WithDefaultDestructurers()
                // next seems very usefull, but mem safe; can try disable it on live if needed
                //.WithIgnoreStackTraceAndTargetSiteExceptionFilter()
                .WithDestructuringDepth(2)             // Aggregate + Inner
                .WithoutReflectionBasedDestructurer()  // slow and dangerious, so disabled
                )
            .Filter
            .ByExcluding(Matching.WithProperty <string>("RequestPath", x => x.StartsWith("info/detail") || x.StartsWith("metrics")));
        }