using System.Text; using System.Text.Json; namespace Core.Telemetry { public class SeqLogger { private readonly string _seqUrl; private readonly string _apiKey; // Optional HttpClient _httpClient; public SeqLogger(HttpClient httpClient, string seqUrl, string apiKey = null) { _seqUrl = seqUrl; _apiKey = apiKey; _httpClient = httpClient; } public async Task LogToSeq(string message, string level, Dictionary properties) { var seqEvent = new Dictionary { { "@t", DateTime.UtcNow.ToString("o") }, { "@mt", message }, { "@l", level } // "Information", "Warning", "Error", etc. }; foreach (var prop in properties) { seqEvent.Add(prop.Key, prop.Value); } var content = new StringContent( JsonSerializer.Serialize(seqEvent), Encoding.UTF8, "application/vnd.serilog.clef"); var response = await _httpClient.PostAsync("/ingest/clef?apiKey=Gt8hS9ClGNfOCAdswDlW", content); response.EnsureSuccessStatusCode(); } } }