Line data Source code
1 : using System;
2 : using cdmdotnet.Logging;
3 : using System.Reflection;
4 :
5 : namespace Cqrs.Configuration
6 : {
7 : public static class ConfigurationExtensions
8 0 : {
9 0 : public static ITelemetryHelper CreateTelemetryHelper(this IConfigurationManager configurationManager, string configurationKey, IDependencyResolver dependencyResolver)
10 : {
11 : return CreateTelemetryHelper(configurationManager, configurationKey, dependencyResolver.Resolve<ICorrelationIdHelper>());
12 : }
13 :
14 0 : public static ITelemetryHelper CreateTelemetryHelper(this IConfigurationManager configurationManager, string configurationKey, ICorrelationIdHelper correlationIdHelper)
15 : {
16 : bool useApplicationInsightTelemetryHelper;
17 : if (!bool.TryParse(configurationManager.GetSetting(configurationKey), out useApplicationInsightTelemetryHelper))
18 : useApplicationInsightTelemetryHelper = false;
19 :
20 : if (useApplicationInsightTelemetryHelper)
21 : {
22 : var helper = (ITelemetryHelper)Activator.CreateInstanceFrom(string.Format("{0}\\cdmdotnet.Logging.Azure.ApplicationInsights.dll", AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory), "cdmdotnet.Logging.Azure.ApplicationInsights.TelemetryHelper", false, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null, new object[] { correlationIdHelper }, null, null).Unwrap();
23 : return helper;
24 : }
25 : return new NullTelemetryHelper();
26 : }
27 : }
28 : }
|