/// <summary>
        ///     Adds a Serilog sink that writes <see cref="T:Serilog.Events.LogEvent">log events</see> to Azure Application Insights.
        /// </summary>
        /// <remarks>
        ///     Supported telemetry types are Traces, Dependencies, Events, Requests and Metrics for which we provide extensions on <see cref="ILogger" />.
        /// </remarks>
        /// <param name="loggerSinkConfiguration">The logger configuration.</param>
        /// <param name="instrumentationKey">The required Application Insights key.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="configureOptions">The optional function to configure additional options to influence the behavior of how the telemetry is logged to Azure Application Insights.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="loggerSinkConfiguration"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="instrumentationKey"/> is blank.</exception>
        public static LoggerConfiguration AzureApplicationInsights(
            this LoggerSinkConfiguration loggerSinkConfiguration,
            string instrumentationKey,
            LogEventLevel restrictedToMinimumLevel,
            Action <ApplicationInsightsSinkOptions> configureOptions)
        {
            Guard.NotNull(loggerSinkConfiguration, nameof(loggerSinkConfiguration), "Requires a logger configuration to add the Azure Application Insights sink to");
            Guard.NotNullOrWhitespace(instrumentationKey, nameof(instrumentationKey), "Requires an instrumentation key to authenticate with Azure Application Insights while sinking telemetry");

            var options = new ApplicationInsightsSinkOptions();

            configureOptions?.Invoke(options);

            return(loggerSinkConfiguration.ApplicationInsights(instrumentationKey, ApplicationInsightsTelemetryConverter.Create(options), restrictedToMinimumLevel));
        }
 /// <summary>
 /// Create an instance of the <see cref="ApplicationInsightsTelemetryConverter"/> class.
 /// </summary>
 /// <param name="options">The optional user-defined configuration options to influence the tracking behavior to Azure Application Insights.</param>
 public static ApplicationInsightsTelemetryConverter Create(ApplicationInsightsSinkOptions options)
 {
     return(new ApplicationInsightsTelemetryConverter(options ?? new ApplicationInsightsSinkOptions()));
 }
 private ApplicationInsightsTelemetryConverter(ApplicationInsightsSinkOptions options)
 {
     Guard.NotNull(options, nameof(options), "Requires a set of options to influence how to track to Application Insights");
     _exceptionTelemetryConverter = new ExceptionTelemetryConverter(options.Exception);
 }