Adds a DebugChannel for TelemetryClient
This commit is contained in:
parent
cdd645bb3b
commit
b2c0919a8c
8 changed files with 203 additions and 47 deletions
|
|
@ -12,7 +12,12 @@
|
|||
<PackageReference Include="Insight.Database" Version="8.0.1" />
|
||||
<PackageReference Include="Insight.Database.Providers.PostgreSQL" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.22.0" />
|
||||
<PackageReference Include="npgsql" Version="9.0.2" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,30 +1,71 @@
|
|||
using Autofac;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
|
||||
|
||||
namespace 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");
|
||||
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 tmc = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault();
|
||||
tmc.ConnectionString = TelemetryConfig.ConnectionString;
|
||||
tmc.TelemetryChannel.DeveloperMode = true;
|
||||
//builder.Register(c =>
|
||||
//{
|
||||
// var channel = new Telemetry.DualTelemetryChannel("C:\\logs\\telemetry.log");
|
||||
// channel.DeveloperMode = true;
|
||||
// var config = new TelemetryConfiguration
|
||||
// {
|
||||
|
||||
//var r = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(tmc);
|
||||
//r.Use(next => new Domain.EventTelemetryEnrichers.EnrichWithMetaTelemetry(next));
|
||||
//r.Build();
|
||||
// ConnectionString = TelemetryConfig.ConnectionString,
|
||||
// TelemetryChannel = channel
|
||||
// };
|
||||
// return new TelemetryClient(config);
|
||||
//}).InstancePerLifetimeScope();
|
||||
|
||||
builder.RegisterInstance(tmc);
|
||||
builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>().InstancePerLifetimeScope();
|
||||
}
|
||||
}
|
||||
var telemetryChannel = new InMemoryChannel
|
||||
{
|
||||
DeveloperMode = true
|
||||
};
|
||||
|
||||
public class TelemetryConfig
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
}
|
||||
//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; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
21
Core/Telemetry/DebugTelemetryChannel.cs
Normal file
21
Core/Telemetry/DebugTelemetryChannel.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.ApplicationInsights.Channel;
|
||||
|
||||
namespace Core.Telemetry
|
||||
{
|
||||
public class DebugTelemetryChannel : InMemoryChannel, ITelemetryChannel
|
||||
{
|
||||
private readonly string _filePath;
|
||||
public ITelemetryChannel _defaultChannel;
|
||||
|
||||
public DebugTelemetryChannel(string filePath)
|
||||
{
|
||||
_filePath = filePath;
|
||||
}
|
||||
public new void Send(ITelemetry item)
|
||||
{
|
||||
base.Send(item);
|
||||
var logEntry = $"{DateTime.UtcNow:u}|{item.Context.Operation.Name}|{item.Context.Operation.Id}";
|
||||
//File.AppendAllText(_filePath, logEntry + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue