2025-01-03 16:21:03 +00:00
|
|
|
|
using Autofac;
|
2025-02-05 18:38:29 +01:00
|
|
|
|
using Microsoft.ApplicationInsights;
|
|
|
|
|
|
using Microsoft.ApplicationInsights.Channel;
|
|
|
|
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
|
|
|
|
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
|
2025-01-03 16:21:03 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Core.ModuleRegistry
|
|
|
|
|
|
{
|
2025-02-05 18:38:29 +01:00
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
//builder.Register(c =>
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var channel = new Telemetry.DualTelemetryChannel("C:\\logs\\telemetry.log");
|
|
|
|
|
|
// channel.DeveloperMode = true;
|
|
|
|
|
|
// var config = new TelemetryConfiguration
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
// ConnectionString = TelemetryConfig.ConnectionString,
|
|
|
|
|
|
// TelemetryChannel = channel
|
|
|
|
|
|
// };
|
|
|
|
|
|
// return new TelemetryClient(config);
|
|
|
|
|
|
//}).InstancePerLifetimeScope();
|
|
|
|
|
|
|
|
|
|
|
|
var telemetryChannel = new InMemoryChannel
|
|
|
|
|
|
{
|
|
|
|
|
|
DeveloperMode = true
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//var configuration = new TelemetryConfiguration
|
|
|
|
|
|
//{
|
|
|
|
|
|
// ConnectionString = TelemetryConfig.ConnectionString,
|
|
|
|
|
|
// TelemetryChannel = telemetryChannel
|
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
|
|
//telemetryChannel.Initialize(configuration);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tmc = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault();
|
|
|
|
|
|
tmc.ConnectionString = TelemetryConfig.ConnectionString;
|
|
|
|
|
|
tmc.TelemetryChannel.DeveloperMode = true;
|
|
|
|
|
|
var channel = new Telemetry.DebugTelemetryChannel("C:\\logs\\telemetry.log");
|
|
|
|
|
|
|
|
|
|
|
|
tmc.TelemetryChannel = channel;
|
|
|
|
|
|
|
|
|
|
|
|
////var r = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(tmc);
|
|
|
|
|
|
////r.Use(next => new Domain.EventTelemetryEnrichers.EnrichWithMetaTelemetry(next));
|
|
|
|
|
|
////r.Build();
|
|
|
|
|
|
|
|
|
|
|
|
//builder.RegisterInstance(configuration);
|
|
|
|
|
|
builder.Register(c => new TelemetryClient(tmc)).InstancePerLifetimeScope();
|
|
|
|
|
|
|
|
|
|
|
|
//builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>()
|
|
|
|
|
|
// .InstancePerLifetimeScope();
|
|
|
|
|
|
|
|
|
|
|
|
//builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>()
|
|
|
|
|
|
// .As<Telemetry.ITelemetryClient>()
|
|
|
|
|
|
// .InstancePerLifetimeScope();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class TelemetryConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public string ConnectionString { get; set; }
|
|
|
|
|
|
}
|
2025-01-03 16:21:03 +00:00
|
|
|
|
}
|