/// <summary>
 /// Adds a Serilog sink that writes <see cref="LogEvent">log events</see> to Microsoft Application Insights
 /// using a custom <see cref="ITelemetry"/> converter / constructor.
 /// </summary>
 /// <param name="loggerConfiguration">The logger configuration.</param>
 /// <param name="telemetryClient">Required Application Insights telemetry client.</param>
 /// <param name="telemetryConverter">Required telemetry converter.</param>
 /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
 /// <returns></returns>
 public static LoggerConfiguration ApplicationInsights(
     this LoggerSinkConfiguration loggerConfiguration,
     TelemetryClient telemetryClient,
     ITelemetryConverter telemetryConverter,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
 {
     return(loggerConfiguration.Sink(new ApplicationInsightsSink(telemetryClient, telemetryConverter), restrictedToMinimumLevel));
 }
        protected ApplicationInsightsTest(ITelemetryConverter converter = null)
        {
            var tc = new TelemetryConfiguration("", _channel = new UnitTestTelemetryChannel());

            Logger = new LoggerConfiguration()
                     .WriteTo.ApplicationInsights(tc, converter ?? TelemetryConverter.Traces)
                     .MinimumLevel.Debug()
                     .Enrich.FromLogContext()
                     .CreateLogger();
        }
        /// <summary>
        /// Adds a Serilog sink that writes <see cref="LogEvent">log events</see> to Microsoft Application Insights
        /// using a custom <see cref="ITelemetry"/> converter / constructor. Only use in rare cases when your application doesn't
        /// have already constructed AI telemetry configuration, which is extremely rare.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="instrumentationKey">Required Application Insights key.</param>
        /// <param name="telemetryConverter">Required telemetry converter.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <returns></returns>
        public static LoggerConfiguration ApplicationInsights(
            this LoggerSinkConfiguration loggerConfiguration,
            string instrumentationKey,
            ITelemetryConverter telemetryConverter,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
        {
            var client = new TelemetryClient();

            if (!string.IsNullOrWhiteSpace(instrumentationKey))
            {
                client.InstrumentationKey = instrumentationKey;
            }

            return(loggerConfiguration.Sink(new ApplicationInsightsSink(client, telemetryConverter), restrictedToMinimumLevel));
        }