Auto stash before merge of "main" and "origin/main"
This commit is contained in:
parent
72544d62e2
commit
5ca874abe9
6 changed files with 81 additions and 14 deletions
51
Core/Telemetry/Class1.cs
Normal file
51
Core/Telemetry/Class1.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using Seq.Api;
|
||||
using Seq.Api.Client;
|
||||
using Seq.Api.Model.Events;
|
||||
using Seq.Api.Model.LogEvents;
|
||||
using Seq.Api.Model.Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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<string, object> properties)
|
||||
{
|
||||
|
||||
var seqEvent = new Dictionary<string, object>
|
||||
{
|
||||
{ "@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue