48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
using Autofac;
|
|
using Microsoft.ApplicationInsights.Channel;
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
|
|
namespace PlanTempus.Core.ModuleRegistry
|
|
{
|
|
public class TelemetryModule : Module
|
|
{
|
|
public TelemetryConfig TelemetryConfig { get; set; }
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
{
|
|
if (TelemetryConfig == null)
|
|
throw new Exceptions.ConfigurationException("TelemetryConfig is missing");
|
|
|
|
|
|
var configuration = TelemetryConfiguration.CreateDefault();
|
|
configuration.ConnectionString = TelemetryConfig.ConnectionString;
|
|
configuration.TelemetryChannel.DeveloperMode = true;
|
|
|
|
if (TelemetryConfig.UseSeqLoggingTelemetryChannel)
|
|
configuration.TelemetryChannel = new Telemetry.SeqLoggingTelemetryChannel(); ;
|
|
|
|
var r = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(configuration);
|
|
r.Use(next => new Telemetry.Enrichers.EnrichWithMetaTelemetry(next));
|
|
r.Build();
|
|
|
|
//builder.RegisterInstance(configuration);
|
|
|
|
//builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>()
|
|
// .InstancePerLifetimeScope();
|
|
|
|
var client = new Microsoft.ApplicationInsights.TelemetryClient(configuration);
|
|
client.Context.GlobalProperties["Application"] = GetType().Namespace.Split('.')[0];
|
|
client.Context.GlobalProperties["MachineName"] = Environment.MachineName;
|
|
client.Context.GlobalProperties["Version"] = Environment.Version.ToString();
|
|
client.Context.GlobalProperties["ProcessorCount"] = Environment.ProcessorCount.ToString();
|
|
|
|
builder.Register(c => client).InstancePerLifetimeScope();
|
|
}
|
|
}
|
|
|
|
public class TelemetryConfig
|
|
{
|
|
public string ConnectionString { get; set; }
|
|
public bool UseSeqLoggingTelemetryChannel { get; set; }
|
|
}
|
|
}
|