Refactoring SetupConsole with DBFactory

This commit is contained in:
Janus C. H. Knudsen 2025-02-21 23:34:06 +01:00
parent 8dd01d291d
commit 78d49a9829
20 changed files with 337 additions and 407 deletions

View file

@ -1,50 +1,27 @@
using Microsoft.ApplicationInsights.Channel;
using System.Net.Http.Headers;
namespace PlanTempus.Core.Telemetry
{
public class SeqLoggingTelemetryChannel : InMemoryChannel, ITelemetryChannel
{
public ITelemetryChannel _defaultChannel;
static HttpClient _client = new HttpClient();
private readonly IMessageChannel<ITelemetry> _messageChannel;
static SeqLoggingTelemetryChannel()
{
_client = new HttpClient()
{
BaseAddress = new Uri("http://localhost:5341"),
Timeout = TimeSpan.FromSeconds(30)
};
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public SeqLoggingTelemetryChannel()
public SeqLoggingTelemetryChannel(IMessageChannel<ITelemetry> messageChannel)
{
_messageChannel = messageChannel;
}
public new void Send(ITelemetry telemetry)
{
//var l = new SeqLogger(_client, "", "");
//l.LogToSeq(
// "Bruger {UserId} loggede ind",
// "Debug",
// new Dictionary<string, object> { { "UserId", "12345" }, { "Counter", "i++" } }
// );
//if (telemetry is Microsoft.ApplicationInsights.DataContracts.TraceTelemetry trace)
//{
// var severity = trace.SeverityLevel;
// Console.WriteLine($"Trace severity: {severity}, Message: {trace.Message}");
//}
var writeTask = _messageChannel.Writer.WriteAsync(telemetry).AsTask();
writeTask.ContinueWith(t =>
{
if (t.Exception != null)
{
throw t.Exception;
}
}, TaskContinuationOptions.OnlyOnFaulted);
base.Send(telemetry);
var logEntry = $"{DateTime.UtcNow:u}|{telemetry.Context.Operation.Name}|{telemetry.Context.Operation.Id}";
//File.AppendAllText(_filePath, logEntry + Environment.NewLine);
}
}
}