Auto stash before merge of "main" and "origin/main"
This commit is contained in:
parent
cb6dd39596
commit
1f675498a2
10 changed files with 148 additions and 30 deletions
|
|
@ -1,14 +1,5 @@
|
|||
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;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Telemetry
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.ApplicationInsights.Channel;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Core.Telemetry
|
||||
{
|
||||
|
|
@ -8,26 +9,38 @@ namespace Core.Telemetry
|
|||
public ITelemetryChannel _defaultChannel;
|
||||
static HttpClient _client = new HttpClient();
|
||||
|
||||
static DebugTelemetryChannel()
|
||||
{
|
||||
_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 DebugTelemetryChannel(string filePath)
|
||||
{
|
||||
_client.BaseAddress = new Uri("http://localhost:5341");
|
||||
_filePath = filePath;
|
||||
}
|
||||
public new void Send(ITelemetry telemetry)
|
||||
{
|
||||
var l = new SeqLogger(_client, "", "");
|
||||
|
||||
//await l.LogToSeq(
|
||||
// "Bruger {UserId} loggede ind",
|
||||
// "Debug",
|
||||
// new Dictionary<string, object> { { "UserId", "12345" }, { "Counter", i++ } }
|
||||
// );
|
||||
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 severity = trace.SeverityLevel;
|
||||
Console.WriteLine($"Trace severity: {severity}, Message: {trace.Message}");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
56
Core/Telemetry/SeqBackgroundService.cs
Normal file
56
Core/Telemetry/SeqBackgroundService.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Telemetry
|
||||
{
|
||||
public class SeqBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly Channel<string> _channel;
|
||||
private readonly HttpClient _client;
|
||||
private readonly string _url;
|
||||
private readonly TelemetryClient _telemetryClient;
|
||||
|
||||
public SeqBackgroundService(TelemetryClient telemetryClient, Configurations.IConfiguration configuration)
|
||||
{
|
||||
_telemetryClient = telemetryClient;
|
||||
_url = configuration["Seq:Url"]; // eller hvor din Seq URL kommer fra
|
||||
_client = new HttpClient();
|
||||
_channel = Channel.CreateUnbounded<string>();
|
||||
}
|
||||
|
||||
public void EnqueueMessage(string message)
|
||||
{
|
||||
_channel.Writer.TryWrite(message);
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await foreach (var message in _channel.Reader.ReadAllAsync(stoppingToken))
|
||||
{
|
||||
await _client.PostAsync(_url, new StringContent(message), stoppingToken);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_telemetryClient.TrackException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_channel.Writer.Complete();
|
||||
await base.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue