Skip to content

Commit

Permalink
Log ApplicationInsightsStartupFilter exceptions (#930)
Browse files Browse the repository at this point in the history
* Log ApplicationInsightsStartupFilter exceptions

- This will end up in application logs instead of logging solely into the event source
  • Loading branch information
davidfowl authored and cijothomas committed Jul 15, 2019
1 parent b631bef commit 12b485f
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

/// <summary>
/// <see cref="IStartupFilter"/> implementation that initialized ApplicationInsights services on application startup
/// </summary>
internal class ApplicationInsightsStartupFilter : IStartupFilter
{
private readonly ILogger<ApplicationInsightsStartupFilter> logger;

public ApplicationInsightsStartupFilter(ILogger<ApplicationInsightsStartupFilter> logger)
{
this.logger = logger;
}

/// <inheritdoc/>
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
Expand All @@ -26,6 +34,7 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
}
catch (Exception ex)
{
this.logger.LogWarning(0, ex, "Failed to resolve TelemetryConfiguration.");
AspNetCoreEventSource.Instance.LogWarning(ex.Message);
}

Expand All @@ -34,4 +43,4 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
};
}
}
}
}

0 comments on commit 12b485f

Please sign in to comment.