2025-02-05 18:38:29 +01:00
|
|
|
|
using Microsoft.ApplicationInsights.Channel;
|
2025-02-11 18:46:51 +01:00
|
|
|
|
using System.Net.Http.Headers;
|
2025-02-05 18:38:29 +01:00
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
namespace PlanTempus.Core.Telemetry
|
2025-02-05 18:38:29 +01:00
|
|
|
|
{
|
2025-02-18 16:23:08 +01:00
|
|
|
|
public class SeqLoggingTelemetryChannel : InMemoryChannel, ITelemetryChannel
|
2025-02-05 18:38:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
public ITelemetryChannel _defaultChannel;
|
2025-02-06 23:46:55 +01:00
|
|
|
|
static HttpClient _client = new HttpClient();
|
2025-02-05 18:38:29 +01:00
|
|
|
|
|
2025-02-18 16:23:08 +01:00
|
|
|
|
static SeqLoggingTelemetryChannel()
|
2025-02-11 18:46:51 +01:00
|
|
|
|
{
|
|
|
|
|
|
_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"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
public SeqLoggingTelemetryChannel()
|
2025-02-05 18:38:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2025-02-06 17:48:24 +01:00
|
|
|
|
public new void Send(ITelemetry telemetry)
|
2025-02-05 18:38:29 +01:00
|
|
|
|
{
|
2025-02-17 17:42:46 +01:00
|
|
|
|
//var l = new SeqLogger(_client, "", "");
|
2025-02-06 23:46:55 +01:00
|
|
|
|
|
2025-02-17 17:42:46 +01:00
|
|
|
|
//l.LogToSeq(
|
|
|
|
|
|
// "Bruger {UserId} loggede ind",
|
|
|
|
|
|
// "Debug",
|
|
|
|
|
|
// new Dictionary<string, object> { { "UserId", "12345" }, { "Counter", "i++" } }
|
|
|
|
|
|
// );
|
2025-02-06 23:46:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
2025-02-17 17:42:46 +01:00
|
|
|
|
//if (telemetry is Microsoft.ApplicationInsights.DataContracts.TraceTelemetry trace)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var severity = trace.SeverityLevel;
|
|
|
|
|
|
// Console.WriteLine($"Trace severity: {severity}, Message: {trace.Message}");
|
|
|
|
|
|
//}
|
2025-02-06 17:48:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base.Send(telemetry);
|
|
|
|
|
|
var logEntry = $"{DateTime.UtcNow:u}|{telemetry.Context.Operation.Name}|{telemetry.Context.Operation.Id}";
|
2025-02-05 18:38:29 +01:00
|
|
|
|
//File.AppendAllText(_filePath, logEntry + Environment.NewLine);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|